WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.326 --> 00:00:05.296 align:middle
We just used blackfire-player
to execute our first "scenario".

00:00:05.866 --> 00:00:12.366 align:middle
It's pretty simple: it goes to the homepage
then clicks the "Log In" link: It works...

00:00:12.656 --> 00:00:16.526 align:middle
but... we're not doing anything
after we visit these pages.

00:00:17.456 --> 00:00:23.096 align:middle
The true power of blackfire-player is
that you can add tests to your scenario -

00:00:23.636 --> 00:00:26.896 align:middle
or even scrape pages and
save that data somewhere.

00:00:27.966 --> 00:00:32.046 align:middle
To add a "test" - or "assertion",
or "expectation"...

00:00:32.316 --> 00:00:34.596 align:middle
I love when things have 5 names...

00:00:35.146 --> 00:00:38.346 align:middle
- say expect followed by - you guessed it!

00:00:38.556 --> 00:00:40.096 align:middle
- an expression!

00:00:40.646 --> 00:00:43.336 align:middle
status_code() == 200.

00:00:44.806 --> 00:00:51.086 align:middle
Copy that and add it to the login page
as well: Ok, try blackfire-player again!

00:00:52.476 --> 00:00:56.776 align:middle
Woo! It still passes and now
it's starting to be useful!

00:00:57.956 --> 00:00:58.766 align:middle
Let's break this down.

00:00:58.846 --> 00:01:05.296 align:middle
First, just like we saw with the
metrics stuff: This is an expression -

00:01:06.036 --> 00:01:10.736 align:middle
it's Symfony's ExpressionLanguage
once again - basically JavaScript.

00:01:11.366 --> 00:01:12.136 align:middle
And second...

00:01:12.646 --> 00:01:16.886 align:middle
this expression has a ton of built-in functions.

00:01:17.966 --> 00:01:21.566 align:middle
Search the blackfire-player
docs for "status_code"...

00:01:21.566 --> 00:01:24.786 align:middle
and keep searching until you
find a big function list.

00:01:25.276 --> 00:01:25.786 align:middle
Here it is.

00:01:26.646 --> 00:01:32.426 align:middle
Yep, we can use current_url(), header()
to get a header value and many others.

00:01:33.586 --> 00:01:40.966 align:middle
The css() function is especially useful: it
allows us to dig into the HTML on the page.

00:01:41.586 --> 00:01:43.066 align:middle
We'll use that in a minute.

00:01:43.876 --> 00:01:48.226 align:middle
The docs also have good examples
of how to do more complex things.

00:01:48.816 --> 00:01:52.786 align:middle
But we're not going to become
Blackfire player experts right now...

00:01:53.086 --> 00:01:56.756 align:middle
I just want you to get comfortable
with writing scenarios.

00:01:57.796 --> 00:02:01.576 align:middle
Let's try to write a failing
expectation to see what it looks like.

00:02:02.536 --> 00:02:03.346 align:middle
Let's see...

00:02:03.436 --> 00:02:08.816 align:middle
we could find this table and assert
that it has more than 500 rows...

00:02:08.926 --> 00:02:11.536 align:middle
which it definitely does not.

00:02:13.346 --> 00:02:15.986 align:middle
Let's find a CSS selector we can use...

00:02:16.866 --> 00:02:22.826 align:middle
hmm. Ok, we could look for a &lt;tbody&gt;
with this js-sightings-list class

00:02:23.106 --> 00:02:25.766 align:middle
and then count its &lt;tr&gt; elements.

00:02:27.146 --> 00:02:30.766 align:middle
Back inside the scenario
file, add another expect.

00:02:31.646 --> 00:02:40.316 align:middle
This time use the css() function and pass it
a CSS selector: tbody.js-sightings-list tr:

00:02:41.846 --> 00:02:48.216 align:middle
Internally, The blackfire-player uses Symfony's
Crawler object from the DomCrawler component,

00:02:48.616 --> 00:02:50.806 align:middle
which has a count() method on it.

00:02:51.856 --> 00:02:53.966 align:middle
Assert that this is &gt; 500.

00:02:53.966 --> 00:02:56.976 align:middle
Let's see what happens!

00:02:58.126 --> 00:02:59.436 align:middle
And... yes!

00:02:59.726 --> 00:03:03.316 align:middle
It fails - with a nice error: The count()

00:03:03.316 --> 00:03:07.866 align:middle
of that CSS element is 25,
which is not greater than 500.

00:03:09.106 --> 00:03:13.856 align:middle
Go back and change this to 10:
The data is dynamic data...

00:03:13.856 --> 00:03:17.656 align:middle
so we don't really know how
many rows it will have.

00:03:18.256 --> 00:03:21.666 align:middle
But since our fixtures add
more than 10 sightings...

00:03:21.666 --> 00:03:26.196 align:middle
and because there will probably be at
least 10 sightings if we ever ran this

00:03:26.236 --> 00:03:30.096 align:middle
against production, this
is probably a safe value.

00:03:31.186 --> 00:03:34.136 align:middle
Try it now: All better!

00:03:35.176 --> 00:03:39.716 align:middle
Another thing that blackfire-player
does well is its errors when I...

00:03:39.716 --> 00:03:41.026 align:middle
do something silly.

00:03:41.836 --> 00:03:47.656 align:middle
Make a typo: change count() to
ount(): And rerun the scenario:

00:03:48.966 --> 00:03:52.006 align:middle
Unable to call method ount of object Crawler.

00:03:53.136 --> 00:03:56.406 align:middle
That's a huge hint to tell
you what object you're working

00:03:56.406 --> 00:04:00.216 align:middle
with so you can figure out
what methods it does have.

00:04:01.446 --> 00:04:05.676 align:middle
Change that back to count(): So...

00:04:05.676 --> 00:04:10.916 align:middle
blackfire-player has nothing to
do with the Blackfire profiler.

00:04:11.526 --> 00:04:18.036 align:middle
It's just a useful tool for visiting pages,
clicking on links and adding expectations.

00:04:18.536 --> 00:04:22.816 align:middle
But... if it truly had nothing
to do with the profiler,

00:04:23.066 --> 00:04:25.506 align:middle
I probably wouldn't have talked about it.

00:04:26.576 --> 00:04:33.566 align:middle
In reality, the concept of "scenarios"
is about to become very important -

00:04:34.366 --> 00:04:39.966 align:middle
it's a fundamental part of a topic we'll
talk about soon: Blackfire "builds".

00:04:40.776 --> 00:04:45.716 align:middle
And actually, there is one little integration
between blackfire-player and the profiler:

00:04:46.266 --> 00:04:49.746 align:middle
you can add performance assertions
to your scenario.

00:04:51.166 --> 00:04:58.686 align:middle
To do that, instead of expect, say assert and
then use any performance expression you want:

00:04:59.216 --> 00:05:02.696 align:middle
the same strings that you can use inside a test.

00:05:02.696 --> 00:05:15.496 align:middle
For example: metrics.sql.queries.count &lt; 30:
When we execute this: It does still pass.

00:05:16.186 --> 00:05:19.426 align:middle
But if you played with this
value - like set it to &lt; 1

00:05:19.546 --> 00:05:25.186 align:middle
and re-ran the scenario: Hmm, it still passes...

00:05:25.706 --> 00:05:30.706 align:middle
even though this page is definitely
making more than one query.

00:05:31.676 --> 00:05:37.066 align:middle
The reason is that the assert
functionality won't work inside a scenario

00:05:37.276 --> 00:05:42.446 align:middle
until we introduce Blackfire
"environments" - which we will soon.

00:05:42.986 --> 00:05:46.306 align:middle
They are one of my absolute
favorite parts of Blackfire.

00:05:46.466 --> 00:05:52.806 align:middle
For now, I'll leave a comment
that this won't work until then:

00:05:52.896 --> 00:05:55.766 align:middle
Next, let's deploy to production!

00:05:56.156 --> 00:06:00.686 align:middle
Because once our site is deployed,
we can finally talk about cool things

00:06:00.686 --> 00:06:02.936 align:middle
like "environments" and "builds".

00:06:03.846 --> 00:06:08.626 align:middle
You can use anything to deploy, of
course, but we will use SymfonyCloud.

