so let's start testing on level application and what we need a Laravel app
and I'll say testing level simple one and it will create the new app and new
app is downloaded successfully so let's open this with our vs code so let's
start testing on a laravel application and with that I am your host Sarthak and
welcome to this channel called bitfilms and if you have not subscribed go and
subscribe to this channel for Laravel and web development related things and don't
forget to hit the bell icon so that you will get the notification so let's see
what we are getting on this level application related to testing so level
is so smart that it will give you PHP unit as a testing tool out of the box so
for that you can go to composer dot JSON file and here you can see a dev
dependencies has PHP unit which we already know we want to install it but
because we are using level we don't have to install it apart from that if you
have watched the previous episode of getting started with PHP unit you have
probably seen that we have created this PHP unit dot XML which is again already
given by level and apart from that we need a test folder where we will put all
our tests and again same thing given by level but it has two folders one is
feature other is unit and two more files so let us talk about feature of us
because we have already talked about unit testing but what is feature and why
it is having a separate folder so the difference between feature test and unit
test you can see it just saying also true and here it's saying go to this ket
that means the base URL and then assert status 200 what's the
difference here so if you are not getting that let me tell you as we know
the unit test is for testing the smallest functions of your code but the
feature test will give you all the way from the user perspective that means you
will test the flow of your application from this feature test so it's ink
whenever user go to the base URL it must have the status code of 200 and that's
exactly the flow of any application whenever you go to the base URL you will
get the page and that means you are getting the 200 response so what if I
run this test so we know we have installed the extension called better
PHP here and because of that we can just run any tests but just by pressing
command R on Mac or ctrl R on windows so you can see as I press the command R it
just running that test and you can see the test name is feature and example
test dot PHP and this test is successful but what if I say get and I will say
about save this file run this test hmm it says the test fails why you know it
says the test you are testing expect 200 but received 4 0 4 and that is why this
test is failing so let's just pass this test why this is failing we know that
there is 4 0 4 that means there is no route called about what if we create the
route so go to web dot PHP and again on the vs code you need to press command P
and search for any file don't try to use your mouse ok
so web dot PHP and here a simple route is a get request having about and giving
it closer hair closest line and returning simple
word about hmm looking nice so what if I run I'm pretty sure this test will pass
which is here and this exactly feature test so what if I do something like this
we want to know whether this about is having this return part or not because
if I comment this out and run the previous test it is still passing but we
are not returning anything what if I want to check so let's create another
test for that so public function about route return something okay so this is
the test we are going to create and don't forgot to give the top box if you
are not giving test prefix here like this okay so this means now we can
simply say just copy paste all these things and like this which is like this
and now we want to say if there is something on the response or not but
what if I died and responds let's comment this out run this test and you
know for running this particular test I clicked here on this test and pressed
controller if I click here press control our hmm it runs this test not this one
so let's click here run the step and yeah we have died dump and now let's do
one more thing and here because we are getting something on the response we can
comment that and now I will check whether we have a bound or not
so assert see about run this test and yes you can see it passes and if I
change something about page and go run this test hmm it is still saying
passes because this include this about but if I remove this about and run the
test it fails yeah you know it fails and that's exactly the feature test is about
so this is good but how I know there is assault
see asserting system on the level so simple you need to go to level
documentation and here on the documentation you will find this testing
part and HTTP tests just go to available assertions and you will see lots and
lots of assertions so this is for about we have created but you know one more
thing yeah we can go to base URL yeah we know this passes because if it is
responding with 200 but we can simply say assert C and level because we have
this assert C and we know this particular ones let me just run the
server and let's open it here yes we can see we have the level on the base page
or piece URL and yes we are getting that okay go to the base URL and see label if
there is a level this test passes run passes super cool if I say Sark does
that is there no it says okay Santa is not present but what if I want to say
you can see we have level then we have documentation so there is one more cool
thing see in order so let's use that C in order and what order we need first
thing first we need level and obviously here inside this we need to give an
array and then it's like doc you men station okay
so let's run this test and yeah this test passes what if I change the order
so this is here and this they're say if this run the test and
boom it fails and this means our test is passing so you can go to this
documentation check out all these assertions there are a bunch of
assertions and feel free to experiment with all these things and this will
enhance your testing knowledge and we will do some more cool stuffs in the
next episode but before that if you have not subscribed this channel please go
and subscribe to this channel and hit the bell I can to get the instant
notification follow bit films on Facebook Twitter and LinkedIn and don't
forget to share this video with your developer friends so we will meet in the
next episode till then good bye