WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:00.976 --> 00:00:04.586 align:middle
Adding specific assertions
inside a test is really cool.

00:00:04.906 --> 00:00:07.696 align:middle
But you can also add assertions globally.

00:00:08.396 --> 00:00:14.396 align:middle
What I mean is, whenever you trigger a real
Blackfire profile - like through your browser -

00:00:14.736 --> 00:00:20.136 align:middle
you can set up assertions that you
want to run against that profile.

00:00:20.816 --> 00:00:24.796 align:middle
Actually, we've already seen a
system that's similar to this.

00:00:25.926 --> 00:00:27.246 align:middle
Click into one of the profiles.

00:00:29.356 --> 00:00:32.626 align:middle
Every profile has a "Recommendations"
tab on the left,

00:00:32.986 --> 00:00:36.506 align:middle
which tells us changes that
we should probably make.

00:00:37.416 --> 00:00:43.056 align:middle
In reality, recommendations
are assertions in disguise!

00:00:43.056 --> 00:00:49.406 align:middle
For example, the "Symfony debug mode should
be disabled in production" is displayed here

00:00:49.406 --> 00:00:51.446 align:middle
because the assertion

00:00:51.446 --> 00:00:58.086 align:middle
that metrics.symfony.kernel.debug.count
equals zero, failed.

00:00:59.176 --> 00:01:01.786 align:middle
Yep, metrics are everywhere!

00:01:02.346 --> 00:01:06.876 align:middle
I love that Blackfire gives us so many
of these recommendations for free.

00:01:07.606 --> 00:01:10.486 align:middle
But we can also define our own.

00:01:11.386 --> 00:01:15.206 align:middle
When we do, they'll show up
under the assertions tab.

00:01:16.256 --> 00:01:17.226 align:middle
How do we do that?

00:01:17.666 --> 00:01:20.946 align:middle
Just send an email to
assertion-requests@blackfire.io,

00:01:20.946 --> 00:01:25.896 align:middle
pay $19.95 for shipping and handling,
and wait 6-8 weeks for delivery.

00:01:26.416 --> 00:01:30.266 align:middle
If you order now, we'll double your
order and include a signed-copy

00:01:30.346 --> 00:01:33.686 align:middle
of the blackfire-player source
code printed as a book.

00:01:34.496 --> 00:01:39.676 align:middle
Or you can configure global assertions
with a special Blackfire config file.

00:01:40.486 --> 00:01:44.976 align:middle
At the root of your project, create
a new file called .blackfire.yaml.

00:01:46.336 --> 00:01:51.206 align:middle
A few different things will eventually
go here - the first is tests:.

00:01:51.596 --> 00:01:55.746 align:middle
Honestly, the trickiest thing about writing
assertions is trying to figure out...

00:01:55.746 --> 00:01:57.486 align:middle
a good assertion to use!

00:01:58.136 --> 00:02:01.266 align:middle
Writing time-based assertions is the easiest...

00:02:01.366 --> 00:02:04.706 align:middle
but because they're fragile,
we want to avoid those.

00:02:05.506 --> 00:02:07.476 align:middle
Let's start with one we've already done.

00:02:08.186 --> 00:02:12.556 align:middle
Say: "HTTP requests should
be limited to 1 per page":.

00:02:14.656 --> 00:02:19.786 align:middle
Below this, add path set to
the regular expression /.

00:02:20.636 --> 00:02:26.676 align:middle
*. This means that this assertion will be
executed against any profile for any page.

00:02:27.386 --> 00:02:31.336 align:middle
Only want the assertion to run
against a single page or section?

00:02:31.726 --> 00:02:33.046 align:middle
Use this option.

00:02:34.156 --> 00:02:36.786 align:middle
Now add assertions: with one item below.

00:02:37.796 --> 00:02:40.516 align:middle
Go steal the metrics expression from our test...

00:02:40.796 --> 00:02:41.596 align:middle
and paste it here.

00:02:44.256 --> 00:02:47.396 align:middle
Change this to be less than or equal to 1.

00:02:48.426 --> 00:02:49.556 align:middle
That's it!

00:02:49.556 --> 00:02:50.246 align:middle
Let's try it out!

00:02:50.736 --> 00:02:51.806 align:middle
Back in your browser...

00:02:52.186 --> 00:02:57.496 align:middle
go back to our site, refresh,
and create a new profile.

00:02:57.496 --> 00:03:03.426 align:middle
I'll call it: [Recording] Added first assertion.

00:03:07.866 --> 00:03:10.246 align:middle
Click into the call graph.

00:03:10.246 --> 00:03:11.456 align:middle
Actually, go back.

00:03:12.136 --> 00:03:13.646 align:middle
See this little green check mark?

00:03:14.206 --> 00:03:19.826 align:middle
That already tells us that this
profile passed all our "tests".

00:03:20.436 --> 00:03:26.506 align:middle
We can see that on the "Assertions"
tab: metrics.http.requests.count was 0,

00:03:26.906 --> 00:03:29.206 align:middle
which is less than or equal to 1.

00:03:30.126 --> 00:03:33.766 align:middle
So at this point, these "tests"
are basically a nice way

00:03:33.766 --> 00:03:36.786 align:middle
to create your own custom recommendations.

00:03:37.366 --> 00:03:42.386 align:middle
These will become more interesting later
when we talk about environments and builds.

00:03:43.456 --> 00:03:49.076 align:middle
Next, let's talk about a tool from the
Blackfire ecosystem called the Blackfire player.

00:03:49.596 --> 00:03:53.486 align:middle
It's a command line utility that
allows us to write simple files

00:03:53.706 --> 00:03:56.376 align:middle
and execute them as functional tests...

00:03:56.696 --> 00:04:00.716 align:middle
completely independent of the
Blackfire profiling system.

00:04:01.416 --> 00:04:06.066 align:middle
What we learn from it will form the
foundation for the rest of the tutorial.

