Install
phpunit:
1. Go to the
root directory of your project (where the '
artisan' file is located).
2. Open '
composer.json. Include phpunit dependency in the JSON.
Save and close the file. After adding the file content should look like:
- {
- "name": "laravel/laravel",
- "description": "The Laravel Framework.",
- "keywords": ["framework", "laravel"],
- "license": "MIT",
- "require": {
- "laravel/framework": "4.0.*",
- "geoip/geoip": "~1.14"
- },
- "require-dev": {
- "phpunit/phpunit": "3.7.*"
- },
- "autoload": {
- "classmap": [
- "app/commands",
- "app/controllers",
- "app/models",
- "app/database/migrations",
- "app/database/seeds",
- "app/tests/TestCase.php"
- ]
- },
- "scripts": {
- "post-install-cmd": [
- "php artisan optimize"
- ],
- "post-update-cmd": [
- "php artisan clear-compiled",
- "php artisan optimize"
- ],
- "post-create-project-cmd": [
- "php artisan key:generate"
- ]
- },
- "config": {
- "preferred-install": "dist"
- },
- "minimum-stability": "dev"
- }
3. Run the following command in that directory :
- composer update
and wait for completion.
4. Now after that run the command "vendor\bin\phpunit" ("vendor/bin/phpunit" for linux)
for running default tests
On Windows run:
- vendor\bin\phpunit
On Linux run:
- vendor/bin/phpunit
You will see something like this:
PHPUnit 3.7.29 by Sebastian Bergmann.
Configuration read from YOUR_PROJECT_DIR\phpunit.xml
.
Time: 188 ms, Memory: 5.50Mb
←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K
7. Now go to the directory YOUR_PROJECT_DIR/app/tests/
8. Open the file 'ExampleTest.php'. It's content should look something like this:
- <?php
- class ExampleTest extends TestCase {
-
- @return
- public function testBasicExample()
- {
- $crawler = $this->client->request('GET', '/');
- $this->assertTrue($this->client->getResponse()->isOk());
- }
- }
- 7. Now write your own test function and call it in testBasicExample():
- class ExampleTest extends TestCase {
-
- @return
- public function testBasicExample()
- {
- $crawler = $this->client->request('GET', '/');
- $this->assertTrue($this->client->getResponse()->isOk());
- self::my_test();
- }
- public function my_test()
- {
- echo 'Hi I want to show you some test results :)';
- }
- }
8. Save and close the file and run again 'vendor\bin\phpunit'.And you will see output like this:
PHPUnit 3.7.29 by Sebastian Bergmann.
Configuration read from F:\laravel\laravelScrapbook\phpunit.xml
.Hi I want to show you test results :)
Time: 172 ms, Memory: 5.50Mb
←[30;42m←[2KOK (1 test, 1 assertion)
←[0m←[2K