[00:00]
welcome to testing php from gary clark
[00:02]
tech let me tell you what this course is
[00:04]
all about the goal of this course is to
[00:06]
show you how to achieve clean code with
[00:09]
maximum test coverage so it may differ
[00:12]
somewhat from other testing resources
[00:14]
you've seen whether that be on testing
[00:16]
php or testing software in general
[00:18]
because
[00:19]
the strategy tends to be to show people
[00:22]
how to use the tools and using fairly
[00:24]
simplistic examples
[00:26]
and there's nothing wrong with that
[00:27]
approach because i've myself i've
[00:29]
recorded videos where i'm showing people
[00:31]
how to use the tools using fairly
[00:33]
simplistic examples and it is probably
[00:35]
the best way to show someone how to use
[00:37]
the tools
[00:38]
but learning how to use the tools is not
[00:42]
learning how to test because you're not
[00:44]
learning how to write code which is
[00:45]
testable you're not learning how to
[00:47]
refactor code to make it more testable
[00:49]
and you're not learning how to approach
[00:50]
different problems from a testing
[00:52]
perspective and so there's a much bigger
[00:55]
problem to solve and that's what this
[00:57]
course aims to address
[01:02]
we're going to approach testing from
[01:03]
different angles we will start out in
[01:05]
the traditional manner i'll show you how
[01:07]
to use the tools and how to configure
[01:09]
them for your specific needs and then
[01:12]
what we'll do is we'll take a small
[01:14]
application which will just be a handful
[01:16]
of small files that i'll provide and
[01:19]
it'll contain no tests but it will
[01:21]
contain some problems which need solving
[01:23]
that provide a challenge to testing and
[01:26]
so we're going to try and gain maximum
[01:28]
test coverage using a combination of
[01:31]
unit tests integration tests and feature
[01:34]
tests which are sometimes also called
[01:36]
functional tests
[01:40]
throughout this we're going to practice
[01:41]
a lot of stuff which will make you a
[01:42]
good developer and a good tester and so
[01:45]
we're talking about things such as
[01:47]
refactoring code to make it more
[01:49]
testable using fake objects testables
[01:52]
can be a confusing subject so i'm going
[01:55]
to make it really clear for you i'll
[01:57]
show you what you should fake why you
[01:58]
should fake it when and how to do it and
[02:01]
also
[02:02]
we'll talk about some of the terminology
[02:04]
such as mocks and stubs is there a
[02:06]
difference between the two what is that
[02:08]
difference we'll also look at things
[02:10]
like static methods are they really an
[02:13]
evil thing that is impossible to test
[02:15]
all of this will be explained in our
[02:18]
integration tests we'll consider how we
[02:21]
can test parts of our application which
[02:23]
communicates with external services that
[02:26]
are outside of our control so we're
[02:28]
talking about things such as third-party
[02:30]
apis which is all part of modern
[02:32]
software development modern web
[02:34]
development we'll also examine database
[02:37]
integration and test that the correct
[02:40]
records can be stored in and retrieved
[02:42]
from a database and while we're on that
[02:44]
subject we'll also consider the
[02:46]
structure of our application and see how
[02:49]
writing good tests can sort of point us
[02:52]
in the direction of actually
[02:54]
creating a more logical structure and a
[02:56]
better separation of concerns and so
[02:59]
we'll also add some new code to our
[03:00]
application which will be backed up by
[03:02]
tests and we'll finish off that part of
[03:04]
the course by adding
[03:06]
feature tests which will cover the whole
[03:07]
process from end to end and that will
[03:10]
give us maximum test coverage that will
[03:12]
lead us nicely into an examination of
[03:15]
code coverage where i'll show you how
[03:17]
you can use tools in order to generate
[03:19]
cold coverage reports and then i'll show
[03:21]
you how you can read these reports in
[03:23]
order to see where you have good test
[03:25]
coverage and which parts of your code
[03:27]
don't have sufficient test coverage and
[03:29]
i'll also explain
[03:31]
some of the limitations of cold coverage
[03:33]
reports called coverage tools and why
[03:35]
cold coverage does not mean the same
[03:37]
thing as functionality coverage or logic
[03:39]
path coverage
[03:43]
up to that point we'll mainly have
[03:45]
tested code which was already written
[03:47]
and we'll have written and refactored
[03:49]
code in order to make it more testable
[03:51]
and these are important skills to have
[03:53]
definitely ones that you'll need however
[03:55]
at this point in the course we're then
[03:57]
going to flip things on the head and
[03:59]
we're going to build a mini application
[04:01]
from scratch using test driven
[04:03]
development the big difference here will
[04:05]
be that we're going to write the tests
[04:07]
first and then we write code to make
[04:10]
those tests pass and then the code which
[04:12]
we have written will guide us and inform
[04:15]
us on what tests we need to write next
[04:21]
this part of the course was a lot of fun
[04:22]
to research and record the application
[04:25]
that we'll build will be able to take
[04:27]
different amounts of money in different
[04:29]
currencies you'll be able to add them
[04:31]
together multiply them do all kinds of
[04:32]
things and then reduce them back down to
[04:35]
a single currency and a single monetary
[04:37]
amount and so if that sounds familiar to
[04:40]
you it's because i borrowed that example
[04:42]
from a book called test driven
[04:44]
development by example by a developer
[04:46]
called kent beck it was originally
[04:48]
written in java and i've converted it to
[04:50]
modern php and it's a really good
[04:52]
example for demonstrating this stuff
[04:54]
because the problem is complex enough to
[04:56]
make it very interesting but at the same
[04:58]
time the other small problems which it
[05:00]
throws up are nice ones for being able
[05:03]
to explain tdd concepts and also the
[05:05]
thinking behind tdd quite clearly and
[05:08]
we'll finish up with a nice clean
[05:10]
application with a minimal code base and
[05:12]
complete test coverage i'm 100 confident
[05:15]
that you'll be able to take what you've
[05:16]
learned in that section walk away and
[05:18]
apply and solve any problem which is
[05:21]
thrown at you testing development can
[05:23]
and probably will make you a better
[05:25]
developer in fact just learning to test
[05:28]
well learning how to combine different
[05:30]
approaches such as the ability to test
[05:33]
already existing code with the ability
[05:35]
to drive out functionality with tests
[05:38]
all of these things will make you a
[05:39]
better developer and i'll be totally
[05:42]
frank with you
[05:43]
learning to test well you will work a
[05:45]
lot less hard than the developers that
[05:47]
don't you'll spend limited amount of
[05:50]
time revisiting code or revisiting work
[05:52]
which is already done and that you
[05:54]
believe to be complete limited time and
[05:56]
bug fixing it'll just be clean code
[05:59]
peace of mind respect from your
[06:00]
colleagues your work won't feel like
[06:02]
work it's all good let's dive in