Who Creates the Controller & Gives it the Container?
…they're the only services that we routinely make public.
If you look back at services.yaml, it's not immediately obvious why they're
public - I don't see a public: true anywhere. I'll save the details for the
next deep-dive tutorial…
Middleware
…want to geek out and see how they work.
So here's our goal: each time we dispatch a message... from anywhere, I want to
attach a unique id to that message and then use that to log what's happening
over time to the…
Edit Endpoint & Deserialization
…Keep the same URL, but change the route name
to admin_article_update_reference - it should be reference, not references,
let's fix that in both places - I don't think I'm referencing that route name
anywhere. And instead of methods={"DELETE"}, use methods={…
Reordering the Files
…nicer. Pass a second argument to create():
an array of options. Pass one called handle set to .drag-handle.
With this, instead of being able to grab anywhere to start sorting, we'll only
be able to grab elements with this class. Down in render…
Absolute Asset Paths
…in one spot: by the uploaded_asset() Twig function. But, we're not actually
using this Twig function anywhere at the moment.
So try this: in the form, we're showing the thumbnail. It might be useful to allow
the user to click this and…
When Existing Tests Break & Exceptions in __construct()
…fency", whatever that is... true to make it active and $this
because it will be attached to this Enclosure.
For the addSecurity() method, because we're not using this method anywhere outside
of this class, we should technically create it as private. But, I already…
Mocks & Spies - shouldBeCalledTimes()
…put the assertion stuff after you run your code. Check this out:
remove the ->shouldBeCalledTimes() line. Then, anywhere after we call
buildEnclosure(), start with $dinosaurFactory->growVelociraptor(Argument::any())
and then ->shouldHaveBeenCalledTimes(2).
This does the exact same thing... it's just a different style. Oh…
Twig
…work most of the time.
It will even look inside your controller to see what kind of object it is and give you
autocomplete on its methods.
And remember, anywhere that you get autocomplete, you can hit command+space to see
all of your options…
Functions, Filters and Debugging with dump
…then use the number_format
to show only one decimal place:
In fact, functions and filters can be used anywhere. Let's use the length
filter to print a message if there are no penguin products for sale:
This filter takes an array or collection…
Doing Crazy things with Foundry & Fixtures
…that's now configured to create
multiple objects. Pass 1, 5 to create anywhere from 1 to 5 QuestionTag objects.
Try the fixtures again:
No errors! And if we SELECT * FROM question:
We only have 25 rows: the correct amount! That's the 20 published.…
Fetching Relations
…refresh, we should see the same list of answers.
And... we don't!? We get some PersistentCollection object. And, even stranger,
I don't see the Answer objects anywhere inside of this collection. Dude, where's
my answers?
Excellent question! Two important things here. First…
Automatic 404 on Unpublished Items
…a Mac, is the same as going to the Refactor menu
on top and selecting "Refactor this". Let's extract this logic to a "Method" - call
it addWhere.
Cool! That gives us a new private function addWhere()... and applyToCollection()
is already calling it. Do the…
Behat Best Practices with Symfony
…Behat is a behavior driven development tool. The name comes from
behavior testing, but that's not documented anywhere that I know about. So it's
a secret for you.
So, what's behavior Liz Keogh says BDD is when you use examples in
conversations…
Role Hierarchy
…
But... don't worry! Symfony has our backs with a sweet feature called
role_hierarchy. Open config/packages/security.yaml. Anywhere inside, I'll
do it above firewalls, add role_hierarchy. Below, put ROLE_ADMIN set to an
array with ROLE_ADMIN_COMMENT and ROLE…
Fetch the User Object
…we can call, getEmail() on it. Do that: ->getEmail():
Cool! Move over and refresh. No errors. Click anywhere down on the web debug
toolbar to get into the profiler. Go to the logs tab, click "Debug" and... down a
bit, there it is!
Checking account…
JavaScript & Page-Specific Assets
…page,
it will appear too early - before even jQuery is included!
To add our new file at the bottom, we can override the javascripts block.
Anywhere in show.html.twig, add {% block javascripts %} and {% endblock %}:
Add the script tag with src="", start typing article_show…
Assets: CSS & JavaScript
…inside the stylesheets block?
Is that important? Well, technically... it doesn't matter: a link tag can live
anywhere in head. But later, we might want to add additional CSS files on specific
pages. By putting the link tags inside this block, we'll have…
Asset Versioning & Cache Busting
… Open config/packages/framework.yaml. Anywhere,
but I'll do it at the bottom, add assets: then json_manifest_path set to
%kernel.project_dir%/public/build/manifest.json:
This is a built-in feature that tells Symfony to look for a JSON file at…
jQuery Plugins / Bootstrap
…! This
is where things get really interesting.
At this point, we're no longer using the global jQuery variable or Bootstrap
JavaScript anywhere: all of our code now uses proper require statements. To
celebrate, remove the two script tags from the base layout:
And now…
PHPUnit: Secure the Park
…failed asserting that false is true on
DinosaurTest line 11.
Ok, let's talk about the basic rules of writing a PHPUnit test. First, you can
technically put your test classes anywhere... but.. you've gotta admit that
tests/ is a pretty good place. Actually…
x
513