[0:00] Today I will walk you through writing Unittest, to test a simple service that converts a [0:01] date format to a different format. [0:09] So let's start the setup by opening the terminal and initializing a composer project, [0:09] I will put the quite flag and let's name our project date service [0:17] and we add the autoload flag with a and we write the src. [0:23] This will allows us to import our service using the PHP use keyword, and we wrote src [0:29] because our service is in the src directory. [0:33] This command will create a vendor directory and the composer.json file that will contain [0:38] our dependencies and project configuration. [0:41] it wrote the name as we wrote in our command and the autoload Date/Service is mapped to [0:48] the src directory, now let's navigate to our Service to insure that it has the correct [0:53] namespace. [0:54] let's correct the namespace like it is defined in the composer.json file. [0:59] Let's navigate back to our composer.json to install phpunit that is used for the unit [1:06] testing, we can use the terminal composer require phpunit/phpunit --dev because this [1:12] dependency is only required in development environment. [1:16] successfully installed. [1:17] let's create a namespace for our test by copying the entry and changing it to the Date/Test [1:26] and the directory should be the "src" a non existente directory that we will create using [1:32] our IDE. and let us create a class into it that is called FormatDateTest. [1:39] As a naming convention the test class should have the method or the class name you would [1:44] like to test and test with uppercase T. let's extend the PHPunit TestCase and let's [1:52] create the class. [1:53] First let me clean up the import. [1:56] and then I will write a test method, as a naming convention test method should start [2:02] with lower case test and the name of our test. [2:08] The purpose of this video is to successfully install phpunit and to insure that it works, [2:14] therefor lets purposly fail our test and write a message: " a message from our test" now [2:21] let's open the terminal and run the test using php vendor/bin/phpunit tests. [2:28] and as you see our test failed successfully, I will expend the terminal to insure that [2:33] our message that we provided is here. [2:36] And there is our message. [2:37] very nice our test seams to be working, one thing we can improve here and that is minimizing [2:43] our test command because it is long!. [2:47] we can do that in the composer.json using the script key: "test" and let's assign it [2:52] to the value that will be executed when the key "test" is called, for us now this is "php [3:00] vendor/bin/phpunit" then let's add our directory "tests" and to better format the output of [3:06] the test in the console we add the --testdox. [3:10] And that's it, let's run now our new command using the composer test. [3:13] our command seams to call the correct value and finally our test failed successfully. [3:19] Ladies and Gentleman this was how to setup composer and phpunit and test using the native [3:26] phpunit command and the composer test, next we will setup the PHPStorm so that we can [3:31] run out test in the IDE, I hope you enjoyed watching and see you next time