├── .gitignore ├── README.md ├── composer.json ├── phpunit.xml ├── src └── STS │ └── Testing │ └── CodeceptionLaravelUnitTest.php └── tests └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .idea 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **This package is no longer maintained. Laravel's built-in testing capabilities have almost entirely replaced Codeception for us, especially with the introduction of Laravel Dusk (browser tests) in Laravel 5.4. If you would like to maintain this package, fork it, let me know, and I'll link to your fork for others to reference.** 2 | 3 | Unit Test class for Codeception and Laravel 5 4 | ==================== 5 | 6 | This class allows you to write [Codeception](http://codeception.com/) unit tests with all the same goodies (bootstrapping, helpers, facade mocking, etc) that the [default Laravel testing](http://laravel.com/docs/4.2/testing) provides. 7 | 8 | **Wait, _unit_ tests in Codeception? I thought Codeception was for functional and acceptance testing?** 9 | 10 | It is. However it can also run [unit tests](http://codeception.com/docs/06-UnitTests) where it "uses PHPUnit as a backend" and adds a few nice helpers. 11 | 12 | **Uh, then why not just PHPUnit with the default Laravel setup?** 13 | 14 | If you are writing your functional/acceptance tests in Codeception (and I encourage it!) then it might be really nice to be able to run all your tests at once for end-to-end testing. This could make automated testing / CI a bit easier. 15 | 16 | And perhaps you also want to take advantage of both the Laravel and Codeception unit test helpers. 17 | 18 | Setup 19 | ==================== 20 | 21 | First off add the composer dependency: 22 | 23 | "require-dev": { 24 | "stechstudio/codeception-laravel-unittest" : "0.1.*" 25 | 26 | Then of course update composer: 27 | 28 | composer update 29 | 30 | Now when writing your Codeception unit tests, extend `STS\Testing\CodeceptionLaravelUnitTest` instead of `\Codeception\TestCase\Test`: 31 | 32 | use STS\Testing\CodeceptionLaravelUnitTest; 33 | 34 | class MyTest extends CodeceptionLaravelUnitTest { 35 | 36 | That's it! Now you can refer to the [Laravel docs](http://laravel.com/docs/4.2/testing) to see the goodies this provides. 37 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stechstudio/codeception-laravel-unittest", 3 | "description": "", 4 | "authors": [ 5 | { 6 | "name": "Joseph Szobody", 7 | "email": "joseph@stechstudio.com" 8 | } 9 | ], 10 | "require": { 11 | "php": ">=5.4.0" 12 | }, 13 | "autoload": { 14 | "psr-0": { 15 | "STS\\Testing": "src/" 16 | } 17 | }, 18 | "minimum-stability": "stable" 19 | } 20 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/STS/Testing/CodeceptionLaravelUnitTest.php: -------------------------------------------------------------------------------- 1 | findBasePath(); 22 | $app = require $basePath . '/bootstrap/app.php'; 23 | $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); 24 | 25 | return $app; 26 | } 27 | 28 | /** 29 | * Setup the test environment. 30 | * 31 | * @return void 32 | */ 33 | public function setUp() 34 | { 35 | if ( ! $this->app) 36 | { 37 | $this->refreshApplication(); 38 | } 39 | 40 | return parent::setUp(); 41 | } 42 | 43 | /** 44 | * Clean up the testing environment before the next test. 45 | * 46 | * @return void 47 | */ 48 | public function tearDown() 49 | { 50 | if ($this->app) 51 | { 52 | $this->app->flush(); 53 | } 54 | 55 | return parent::tearDown(); 56 | } 57 | 58 | /** 59 | * Figure out the base Laravel path 60 | * 61 | * @return string 62 | */ 63 | protected function findBasePath() 64 | { 65 | // Assuming that tests are running inside a folder called /test/..., and that folder 66 | // is in the base Laravel folder, this is easy. 67 | $reflector = new \ReflectionClass(get_called_class()); 68 | $currentPath = $reflector->getFileName(); 69 | $basePath = substr($currentPath,0, strpos($currentPath, "/tests/")); 70 | 71 | if(file_exists($basePath . '/bootstrap/app.php')) { 72 | return $basePath; 73 | } 74 | 75 | // We couldn't figure it out automatically, let's look for help 76 | if(defined('LARAVEL_BASE') && file_exists(LARAVEL_BASE . '/bootstrap/app.php')) { 77 | return LARAVEL_BASE; 78 | } 79 | 80 | // We need to full out exit here, not just throw an exception 81 | print("Unable to determine your base Laravel path, and didn't find a valid LARAVEL_BASE defined. Please define that in your _bootstrap.php file."); 82 | exit(1); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stechstudio/codeception-laravel-unittest/8a36376fea49b17da1ce5da9f757466279f17fe8/tests/.gitkeep --------------------------------------------------------------------------------