so in the last episode we have installed phpunit
and created this PHP unit dot XML file and here we have defined firstly the XML
version tag simple one then we are giving this bootstrapped to start from
there then we are saying that ok whenever you are running the test
giveme result in colors then verbose that means give some more information
and whenever you have any failed test just stop executing other tests and then
we are defining theft suits and then one test suit singular one and naming it
unit and defining that ok every test is now inside tests folder here it is the
tests folder we have created unit folder inside this and inside this we will
create our test but before creating the test you can see to run a test we need
to say vendor slash bin slash PHP unit and that will run the test because we
don't have any tests that's why we are getting no tests executed but this is I
don't like ok so what I need I need to have a simple flow to run the test for
that you need to go and install a package or extension for this VX code so
let's press control-shift and X for windows user and command shift in X for
Mac user to have this extension window open on the left side then you need to
type here better PHP unit search for this thing and if it is not giving let's
search like this so second one better PHP unit so let's just install it reload
this vyas code and now press ctrl shift and E or command shift and E to go back
to this Explorer and if I now want to run the test
so let's even close this terminal I want to run the test
so what I will do I will press control-shift and P for Windows user end
command shift + P for Mac user and now I will say run and you can 3 we have this
better PHP or even just simple search for better PHP so let's say better PHP
and hit enter and you can see it says document of
undefined it says better PHP unit open a file to
run command so what happening here we are saying - better be a few that you
need to run a test but where is the test there is no test so let's create a test
now so let's close this window and here in this unit folder let's
create a file called first that has to be first test dot PHP
initialize PHP tag in here let's create a class and class name is first test and
this is going to extend and this is going to extend which thing this is
going to extend our PHP unit tests so it will be like test case so this test case
has to be this one PHP unit framework test case not Celestion bergman and all
these things just this one and because this is created and yeah we have done
this now again let's try our better PHP so command shift P or ctrl shift P for
Windows user better PHP unit hit enter 10 yeah you can see it says tests 1
assertion 0 warning 1 this means it is working that means the better PHP is
working but even that you can see if I type this command shift + P again with
we have shortcuts command K or command R right now I am on this class I will say
command R hmm it's not doing that so let's go to
preferences keyboard shortcuts and hair let's search for better PHP so better
PHP yeah we have this so keybinding is ctrl R so why not make this ctrl R and
yes it is done so if I go here and press
ctrl R it run the test so close this and yeah this is good but what if the file
is closed and if I press ctrl R hmm it says again eh what you are going to run
I don't know so again if you go to preferences and
keyboard shortcuts you will see that it says run previous previous one so why
not run why not give a shortcut to run the previous one I will give ctrl shift
in are for running the previous command or previous test so here we have let's
say control R to run this test that's good close this line ctrl shift and are
the head will execute your last test so right now we don't have any test so yeah
we are going to write the test so this is good let's say public function and
for every function if that is a test you need to prefix word test so test first
time but it will be better if you give your test name descriptive so what I
will say test and our test is multiplication of two number so multi
vacation and I will use camel case of two number so this is good and to assert
something you need to simply say dollar this arrow assert and assert what let's
say assert true okay and inside this whatever you give so what it's like
whatever you give inside parenthesis if that returns true it will say okay you
are expert tink true that means asserting true and
you are getting true so let's say drew here and because I am on this function
if I press command R or control ARF it will execute the test and you can
see if we have okay one test one assertion and that is on the green
colored color that's good nice so this is good but as you you can
see if I say here false and you know I have a close this window and if I press
command shift are or control shift are for PC users windows users it will
execute the last one and which is saying okay it fills why it fails and you have
the description why it fills because first test this the test name actually
failed asserting that false is true you are getting false expecting true that's
why this test fails so let's now go and once more make something so I have one
variable called 5 another variable called let's say 4 and I want to
multiply it so there is multiplication so C will be 5 multiplied by 4 and we
know five fours are 20 so what we are expecting here asserting 20 so C has to
be 20 but how we can assert that the value of C has to be 20 so it's like
assert and what we are going to assert assert equal equals which thing we need
to provide two things that has to be equal so assert C has to be equal to 20
this is good so now run the test control our hand it says asserted and
successfully done but what if I say 21 to 0 1 is ok also and control are it
fails and this is exactly how you can use peach
unit just from the scratch so before moving to the next video let's just
tweak something you know whenever you are writing the test you need to make
sure the function name has to be descriptive and descriptive name becomes
longer and if I see it directly I can't see exact what I have written so why not
do one thing so I will use instead of camel case I will separate each word
with underscore to have a better clarity so like this and test multiplication of
two number and if I try this yes it is still working
oh yeah we know it has to be 20 to pass this test that's okay and this is more
clear in terms of readability the next thing is you can see for every test if
we don't use this test prefix here if I save run the test
it says no tests executed you need to make sure the test has to be there the
word test initially prefix it but instead of this you can do one thing
more you can just create the dog boxers and that will be like Flash /to astrick
and then your dogs and then the s trick and again forward slash so here you need
to say at test if I remove this and try to run it yeah it says no test executed
but if I write this one run it yes you can see it says one tested and that is
successful so just use these little tips to make your test more clear and faster
and if you have liked this episode and if you have not subscribed just go and
subscribe to this channel and don't forgot to hit the bell I can to get the
notification whenever I upload any video follow bit films on Facebook Twitter
Instagram and LinkedIn and we will meet in the next episode till then good bye