WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:02.016 --> 00:00:07.356 align:middle
Here's the question now: how can we make
our test app use the pull request code

00:00:07.396 --> 00:00:09.396 align:middle
from the symfony/ directory?

00:00:10.636 --> 00:00:16.406 align:middle
Check out the vendor/symfony directory in the
app: it's just a bunch of sub-directories,

00:00:16.636 --> 00:00:19.566 align:middle
each containing code from
Symfony's master branch.

00:00:21.036 --> 00:00:27.566 align:middle
But, what we really want is for this validator
directory to instead be a symbolic link

00:00:27.566 --> 00:00:32.856 align:middle
to the correct path in our symfony/
directory: src/Symfony/Component/Validator.

00:00:34.016 --> 00:00:36.156 align:middle
We could do this by hand...

00:00:36.576 --> 00:00:43.646 align:middle
but! Symfony has a cool script to do
this automatically: it's called link.

00:00:43.646 --> 00:00:56.476 align:middle
Go back to the terminal that holds the
app and run: ls -la vendor/symfony Yep!

00:00:56.476 --> 00:00:58.716 align:middle
Just a bunch of lonely directories.

00:00:59.466 --> 00:01:01.066 align:middle
Go back to the other tab and run .

00:01:02.206 --> 00:01:04.646 align:middle
/link and point to our app: ..

00:01:05.096 --> 00:01:10.156 align:middle
/triage_pr_28069: Wow!

00:01:10.836 --> 00:01:20.196 align:middle
Go back to your app and check the symfony
directory again: ls -la vendor/symfony Awesome!

00:01:21.146 --> 00:01:22.626 align:middle
Every package that comes

00:01:22.626 --> 00:01:28.276 align:middle
from the symfony/symfony repository
is now a symlink to our local copy!

00:01:29.196 --> 00:01:32.986 align:middle
In other words, our app is
now using Colin's code!

00:01:32.986 --> 00:01:37.656 align:middle
It's time for us to write some
code that tests the new validator!

00:01:38.866 --> 00:01:45.056 align:middle
In src/, create a new PHP class,
um, how about: ClassToValidate.

00:01:45.796 --> 00:01:46.906 align:middle
I'm feeling creative!

00:01:48.086 --> 00:01:51.756 align:middle
Inside add a new public property
called enteredNumber.

00:01:52.436 --> 00:01:58.036 align:middle
I'm trying to keep my code as simple as
possible: a public property is a nice shortcut.

00:01:59.406 --> 00:02:05.496 align:middle
Next, add the annotation:
@Assert\MultipleOf() of 10.

00:02:06.686 --> 00:02:13.276 align:middle
I'm also going to add a second annotation
that will eventually fail - @Assert\Blank() -

00:02:13.706 --> 00:02:16.136 align:middle
just to make sure everything is working ok.

00:02:17.576 --> 00:02:23.606 align:middle
To try this, in the Controller/ directory,
create a new class: TestingController.

00:02:23.696 --> 00:02:27.556 align:middle
Fill in the namespace: App\Controller.

00:02:28.696 --> 00:02:31.836 align:middle
Because we have multiple
apps in one PhpStorm project,

00:02:32.076 --> 00:02:34.876 align:middle
some of the magic we normally get isn't working.

00:02:37.506 --> 00:02:39.976 align:middle
Inside this, add public function test().

00:02:41.246 --> 00:02:47.616 align:middle
Ok: to test validation we'll need the
validator service and the object to validate.

00:02:48.816 --> 00:02:53.556 align:middle
And an argument: ValidatorInterface $validator.

00:02:56.246 --> 00:03:05.276 align:middle
Then, $myObject = new ClassToValidate()
and set its enteredNumber to 10.

00:03:06.636 --> 00:03:13.376 align:middle
Oh, and change the MultipleOf to be 5:
we'll test that 10 is a multiple of 5.

00:03:14.636 --> 00:03:20.056 align:middle
To validate, add $errors =
$validator-&gt;validate($myObject);.

00:03:21.606 --> 00:03:24.356 align:middle
Then, dump that and die!

00:03:25.346 --> 00:03:27.836 align:middle
Finally, we need a route for this!

00:03:28.736 --> 00:03:34.646 align:middle
We don't have annotations installed, so, to
keep things simple, add this in routes.yaml:

00:03:34.926 --> 00:03:41.146 align:middle
uncomment the example, and change the
controller to TestingController::test.

00:03:42.236 --> 00:03:49.026 align:middle
Done! Back in the terminal, start the built-in
PHP web server in the public/ directory:

00:03:49.026 --> 00:03:58.006 align:middle
php -S localhost:8000 -t public We're ready!

00:03:59.666 --> 00:04:04.176 align:middle
Find your browser, go to
http://localhost:8000 and...

00:04:04.636 --> 00:04:08.176 align:middle
what?! No validation errors!

00:04:09.386 --> 00:04:16.666 align:middle
That's actually not good - the @Blank
constraint should give us one error.

00:04:18.076 --> 00:04:24.116 align:middle
The problem is that our setup is not quite
complete: to use annotations with the validator,

00:04:24.376 --> 00:04:27.106 align:middle
you need to install the annotations library.

00:04:27.236 --> 00:04:35.726 align:middle
Stop the web server and run:
composer require annotations This

00:04:35.726 --> 00:04:38.486 align:middle
installs sensio/framework-extra-bundle...

00:04:38.756 --> 00:04:42.946 align:middle
we only technically need to
install doctrine/annotations.

00:04:43.246 --> 00:04:44.186 align:middle
But, that's ok.

00:04:45.346 --> 00:04:50.396 align:middle
Restart the built in web
server: Move over and, refresh.

00:04:51.976 --> 00:04:57.086 align:middle
It works! We get the one
expected error from @Assert\Blank,

00:04:58.556 --> 00:05:04.896 align:middle
but we do not get a second
error: 10 is a multiple of 5.

00:05:06.056 --> 00:05:12.776 align:middle
To make sure the failure works,
change this to 9, move over and...

00:05:13.186 --> 00:05:15.756 align:middle
yes! There is the second error.

00:05:16.376 --> 00:05:18.586 align:middle
That error language looks really nice to me.

00:05:19.846 --> 00:05:21.476 align:middle
Hey! The code works!

00:05:21.736 --> 00:05:23.606 align:middle
This is great news!

00:05:24.976 --> 00:05:27.456 align:middle
Let's go back to GitHub and tell the world!

00:05:27.956 --> 00:05:29.926 align:middle
I'll "Approve" this pull request.

00:05:30.616 --> 00:05:33.786 align:middle
And, like everything, don't
worry: this doesn't mean

00:05:33.786 --> 00:05:38.176 align:middle
that the PR is definitely perfect:
just that you think it's ready.

00:05:38.916 --> 00:05:42.046 align:middle
The really important part is
to add as much information

00:05:42.046 --> 00:05:45.516 align:middle
about why you think it's ready or not ready.

00:05:46.086 --> 00:05:51.776 align:middle
In this case, we checked the code and we
actually tested this in a real project.

00:05:52.616 --> 00:05:54.506 align:middle
And... approve!

00:05:56.606 --> 00:05:59.296 align:middle
Oh, but I did forget to check one thing:

00:05:59.606 --> 00:06:04.586 align:middle
whether or not this new feature has a
documentation pull request or issue.

00:06:05.556 --> 00:06:07.996 align:middle
But, of course, it does!

00:06:08.586 --> 00:06:14.896 align:middle
Not every pull request needs documentation -
but, if you think it does, and it's missing,

00:06:15.356 --> 00:06:17.496 align:middle
gently poke the pull request author.

00:06:17.856 --> 00:06:19.126 align:middle
Or, even better!

00:06:19.516 --> 00:06:22.076 align:middle
Go create the documentation
pull request yourself!

00:06:22.366 --> 00:06:23.596 align:middle
We'll do that later.

00:06:24.716 --> 00:06:26.476 align:middle
Oh, and fun fact!

00:06:26.866 --> 00:06:31.446 align:middle
This feature was merged about 1
week after we did this review.

00:06:31.996 --> 00:06:33.356 align:middle
Go open source!

00:06:34.176 --> 00:06:40.066 align:middle
After some good community feedback, it was
renamed from MultipleOf to DivisibleBy.

00:06:40.436 --> 00:06:41.786 align:middle
A great change!

00:06:42.596 --> 00:06:46.476 align:middle
Next, let's triage an issue
and try to close a bug.

