{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"Testbench","type":"basic","slug":"testbench","excerpt":"Testbench Component for Laravel","body":"Testbench Component bring Laravel Framework testing features to Laravel package.\n\n* [Installation](#installation)\n* [Configuration](#configuration) \n* [Usage](#usage)\n* [Alternative 3rd Party Testing](#alternative-3rd-party-testing)\n* [Troubleshooting](#troubleshooting)\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Installation\"\n}\n[/block]\nYou can either update the `composer.json` file and run `composer install` or run `composer require` directly:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"{\\n \\\"require-dev\\\": {\\n \\\"orchestra/testbench\\\": \\\"~3.0\\\"\\n }\\n}\",\n \"language\": \"json\",\n \"name\": \"composer.json\"\n },\n {\n \"code\": \"composer require --dev \\\"orchestra/testbench=~3.0\\\"\",\n \"language\": \"text\",\n \"name\": \"Terminal\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Usage\"\n}\n[/block]\nTo use Testbench Component, all you need to do is extend `Orchestra\\Testbench\\TestCase` instead of `PHPUnit_Framework_TestCase`. The fixture app booted by `Orchestra\\Testbench\\TestCase` is predefined to follow the base application skeleton of Laravel 5.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n\\t//\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Custom Service Providers\n\nTo load your package service provider, override the `getPackageProviders()`.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function getPackageProviders($app)\\n {\\n\\t\\treturn ['Acme\\\\AcmeServiceProvider'];\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Custom Aliases\n\nTo load your package alias, override the `getPackageAliases`.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function getPackageAliases($app)\\n {\\n\\t\\treturn [\\n \\t'Acme' => 'Acme\\\\Facade'\\n ];\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Overriding setUp() method\n\nSince `Orchestra\\Testbench\\TestCase` replace Laravel's `Illuminate\\Foundation\\Testing\\TestCase`, if you need your own `setUp()` implementation, do not forget to call `parent::setUp()`:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function setUp()\\n {\\n\\t\\tparent::setUp();\\n \\n // Your code here\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\nIf you need to add something early in the application bootstrapping process, you could use the `getEnvironmentSetUp()` method:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function getEnvironmentSetUp($app)\\n {\\n # Setup default database to use sqlite :memory:\\n $app['config']->set('database.default', 'testbench');\\n $app['config']->set('database.connections.testbench', [\\n 'driver' => 'sqlite',\\n 'database' => ':memory:',\\n 'prefix' => '',\\n ]);\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Overriding Console Kernel\n\nYou can easily swap Console Kernel for application bootstrap by overriding `resolveApplicationConsoleKernel()` method:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function resolveApplicationConsoleKernel($app)\\n {\\n $app->singleton('Illuminate\\\\Contracts\\\\Console\\\\Kernel', 'Acme\\\\Testbench\\\\Console\\\\Kernel');\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Overriding HTTP Kernel\n\nYou can easily swap HTTP Kernel for application bootstrap by overriding `resolveApplicationHttpKernel()` method:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function resolveApplicationHttpKernel($app)\\n {\\n $app->singleton('Illuminate\\\\Contracts\\\\Http\\\\Kernel', 'Acme\\\\Testbench\\\\Http\\\\Kernel');\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Overriding Application Timezone\n\nYou can also easily override application default timezone, instead of the default `\"UTC\"`:\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function getApplicationTimezone($app)\\n {\\n return 'Asia/Kuala_Lumpur';\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Using Migrations\n\nTestbench include a custom migrations command that support `realpath` option instead of the basic relative `path` option, this would make it easier for you to run database migrations during testing by just including the full realpath to your package `database/migration` folder.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function setUp()\\n {\\n\\t\\tparent::setUp();\\n \\n $this->artisan('migrate', [\\n '--database' => 'testbench',\\n '--realpath' => realpath(__DIR__.'/../migrations'),\\n ]);\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n## Using Model Factories\n\nTestbench include `withFactories()` method to allow you to register custom model factory path for your test suite.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<?php\\n\\nclass TestCase extends Orchestra\\\\Testbench\\\\TestCase\\n{\\n \\n /* ... */\\n \\n protected function setUp()\\n {\\n\\t\\tparent::setUp();\\n \\n $this->withFactories(__DIR__.'/factories');\\n\\t}\\n}\",\n \"language\": \"php\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Alternative 3rd Party Testing\"\n}\n[/block]\nThere also 3rd party packages that extends Testbench Component on CodeCeption and PHPSpec:\n\n* [Testbench with CodeCeption](https://bitbucket.org/aedart/testing-laravel)\n* [Testbench with PHPSpec](https://github.com/Pixelindustries/phpspec-testbench)\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Troubleshooting\"\n}\n[/block]\n## No supported encrypter found. The cipher and / or key length are invalid.\n\n> RuntimeException: No supported encrypter found. The cipher and / or key length are invalid.\n\nThis error would only occur if your test suite require actual usage of the encrypter. To solve this you can add a dummy `APP_KEY` or use a specific key to your application/package `phpunit.xml`.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"<phpunit>\\n\\n\\t// ...\\n\\n\\t<php>\\n <env name=\\\"APP_KEY\\\" value=\\\"AckfSECXIvnK5r28GVIWUAxmbBSjTsmF\\\"/>\\n </php>\\n\\n</phpunit>\",\n \"language\": \"xml\",\n \"name\": \"phpunit.xml\"\n }\n ]\n}\n[/block]","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5772130888dd9819003d3878","project":"576ebdb79c84a31900958aba","version":{"version":"3.3","version_clean":"3.3.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["576ebdb79c84a31900958abe","576ebfc59c84a31900958ac4","576ec32f52f96619007cfb9a","576ec7b7560eef0e00cd3096","576ed4249c84a31900958add","576ed429560eef0e00cd30a3","576ed43a52f96619007cfbb5","576ed44d5a8c72170082b794","577212f20da40019004f0816","57725c7e0a6d610e00de9e4c"],"_id":"576ebdb79c84a31900958abd","project":"576ebdb79c84a31900958aba","releaseDate":"2016-06-25T17:21:59.854Z","__v":10,"createdAt":"2016-06-25T17:21:59.854Z"},"createdAt":"2016-06-28T06:02:48.002Z","user":"576ebd239c84a31900958ab9","githubsync":"","__v":21,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Components","slug":"components","order":8,"from_sync":false,"reference":false,"_id":"577212f20da40019004f0816","version":"576ebdb79c84a31900958abd","__v":0,"project":"576ebdb79c84a31900958aba","createdAt":"2016-06-28T06:02:26.465Z"},"parentDoc":null}
Testbench
Testbench Component for Laravel