{"id":22821846,"url":"https://github.com/benconstable/phpspec-laravel","last_synced_at":"2025-04-05T04:11:10.139Z","repository":{"id":14865538,"uuid":"17588965","full_name":"BenConstable/phpspec-laravel","owner":"BenConstable","description":"Test your Laravel applications with phpspec","archived":false,"fork":false,"pushed_at":"2019-06-24T05:08:09.000Z","size":110,"stargazers_count":145,"open_issues_count":4,"forks_count":47,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-29T03:06:58.091Z","etag":null,"topics":["laravel","php","phpspec","testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenConstable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-10T10:22:29.000Z","updated_at":"2024-06-26T08:20:48.000Z","dependencies_parsed_at":"2022-09-05T03:40:58.529Z","dependency_job_id":null,"html_url":"https://github.com/BenConstable/phpspec-laravel","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Fphpspec-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Fphpspec-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Fphpspec-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenConstable%2Fphpspec-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenConstable","download_url":"https://codeload.github.com/BenConstable/phpspec-laravel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247284949,"owners_count":20913704,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","php","phpspec","testing"],"created_at":"2024-12-12T16:09:11.721Z","updated_at":"2025-04-05T04:11:10.118Z","avatar_url":"https://github.com/BenConstable.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phpspec Laravel Extension\n\n\u003e [phpspec](http://www.phpspec.net/) extension for testing [Laravel](http://laravel.com/)\n  applications.\n\n[![Build Status](https://travis-ci.org/BenConstable/phpspec-laravel.svg?branch=master)](https://travis-ci.org/BenConstable/phpspec-laravel)\n[![Latest Stable Version](https://poser.pugx.org/benconstable/phpspec-laravel/v/stable.png)](https://packagist.org/packages/benconstable/phpspec-laravel)\n[![Total Downloads](https://poser.pugx.org/benconstable/phpspec-laravel/downloads.png)](https://packagist.org/packages/benconstable/phpspec-laravel)\n[![License](https://poser.pugx.org/benconstable/phpspec-laravel/license.svg)](https://packagist.org/packages/benconstable/phpspec-laravel)\n\n## Versions\n\nDepending on the version of Laravel and/or Phpspec you're using, you'll want to make sure that\nyou're using the version of this package that's right for you. Use the table below to pick\nthe right one.\n\n| PHP Version | Package Version | Laravel Version | Phpspec Version |\n| ----------- | --------------- | --------------- | --------------- |\n| `\u003e=5.3.0`   | `^v1.2`         | `^v4.1`         | `^v2.0`         |\n| `\u003e=5.4.0`   | `^v2.0`         | `v5.0-v5.3`     | `^v2.1`         |\n| `\u003e=5.6.0`   | `^v3.0`         | `^v5.1-v5.4`    | `^v3.0`         |\n| `\u003e=7.0.0`   | `^v4.0`         | `^v5.4`         | `^v4.0`         |\n\n## Installation\n\nInstall the package with composer:\n\n```\ncomposer require --dev \"benconstable/phpspec-laravel:~4.0\"\n```\n\nthen add this to your `phpspec.yml`:\n\n```yaml\nextensions:\n  PhpSpec\\Laravel\\Extension\\LaravelExtension: ~\n```\n\nYou can take a look at [`example.phpspec.yml`](https://github.com/BenConstable/phpspec-laravel/blob/master/example.phpspec.yml)\nfor a good set of sensible phpspec defaults for a Laravel project.\n\n## Why this extension?\n\nThis extension provides you with a bootstrapped Laravel environment when writing\nyour phpspec tests.\n\nIt allows you to make use of some of the nice features that Laravel provides, like\nclass aliases and helper functions, without being hindered by your testing framework.\n\nThis extension **is not** a swap-in replacement for Laravel's built in PHPUnit setup.\nIf you'd like integration and/or functional tests, please use that,\n[Behat](http://behat.org/), or [Codeception](http://codeception.com/).\n\n## Configuration\n\n### Testing environment\n\nBy default, the extension bootstraps Laravel in the `testing` environment. You\ncan change this to production (or whatever you like) by setting:\n\n```yaml\nextensions:\n  PhpSpec\\Laravel\\Extension\\LaravelExtension:\n    testing_environment: \"production\"\n```\n\nin your `phpspec.yml`.\n\n### App bootstrap path\n\nBy default, the extension will bootstrap your app by looking for `bootstrap/app.php`\nin the directory above `vendor/`. This is the default location that Laravel\nprovides.\n\nYou can manually specify the path to the bootstrap file if you're using a non-standard\ninstallation, like so:\n\n```yaml\nextensions:\n  PhpSpec\\Laravel\\Extension\\LaravelExtension:\n    framework_path: \"/non/standard/laravel/setup/app.php\"\n```\n\nYou can specify either an absolute path (use leading slash), or a path relative\nto the `vendor/` directory.\n\n## Usage\n\n### Testing without Laravel\n\nIf you're not using any code specific to the Laravel environment, then you don't\nneed to do anything differently. Just write your phpspec tests as normal!\n\n### Testing with Laravel\n\nIf you want to take advantage of Laravel's aliases, or use some of its\n[helper functions](https://laravel.com/docs/5.4/helpers), extend your specs\nfrom `PhpSpec\\Laravel\\LaravelObjectBehavior`. This will prevent errors when\ntesting.\n\n**For example, this class uses an alias:**\n\n```php\n\u003c?php\nnamespace App;\n\nuse Inspiring;\n\nclass MyInspiring extends Inspiring\n{\n    public function quoteBackwards()\n    {\n        return strrev(parent::quote());\n    }\n}\n```\n\nand without extending from `PhpSpec\\Laravel\\LaravelObjectBehavior`:\n\n```php\n\u003c?php\nnamespace spec\\App;\n\nuse PhpSpec\\ObjectBehavior;\n\nclass MyInspiringSpec extends ObjectBehavior\n{\n    function it_inspires_backwards()\n    {\n        $this-\u003equoteBackwards()-\u003eshouldBeString();\n    }\n}\n```\n\nyou'll get `Fatal error: Class 'Inspiring' not found...`. But extending from `PhpSpec\\Laravel\\LaravelObjectBehavior`:\n\n```php\n\u003c?php\nnamespace spec\\App;\n\nuse PhpSpec\\Laravel\\LaravelObjectBehavior;\n\nclass MyInspiringSpec extends LaravelObjectBehavior\n{\n    function it_inspires_backwards()\n    {\n        $this-\u003equoteBackwards()-\u003eshouldBeString();\n    }\n}\n```\n\nyou'll get `✔ inspires backwards`.\n\n**and this class uses a helper function:**\n\n```php\n\u003c?php\nnamespace App;\n\nclass MyEncryptor\n{\n    public function encrypt($arg)\n    {\n        return bcrypt($arg);\n    }\n}\n```\n\nand without extending from `PhpSpec\\Laravel\\LaravelObjectBehavior`:\n\n```php\n\u003c?php\nnamespace spec\\App;\n\nuse PhpSpec\\ObjectBehavior;\n\nclass MyEncryptor extends ObjectBehavior\n{\n    function it_encrypts_a_string()\n    {\n        $this-\u003eencrypt()-\u003eshouldBeString();\n    }\n}\n```\n\nyou'll get `Fatal error: Call to a member function make() on a non-object...`.\nBut extending from `PhpSpec\\Laravel\\LaravelObjectBehavior`:\n\n```php\n\u003c?php\nnamespace spec\\App;\n\nuse PhpSpec\\Laravel\\LaravelObjectBehavior;\n\nclass MyEncryptor extends LaravelObjectBehavior\n{\n    function it_encrypts_a_string()\n    {\n        $this-\u003eencrypt()-\u003eshouldBeString();\n    }\n}\n```\n\nyou'll get `✔ encrypts a string`.\n\n### Accessing the IoC container\n\nIf you need to access the [Service Container](http://laravel.com/docs/5.0/container)\nin your specs, just use the `app()` helper!\n\n## Learning more about phpspec and Laravel\n\n[Laracasts](https://laracasts.com/) has some great guides on phpspec and Laravel.\n['Laravel, phpspec and refactoring'](https://laracasts.com/lessons/phpspec-laravel-and-refactoring)\nis a good starting point; it shows how you should use phpspec with Laravel,\nand covers the basics of writing tests (and it's free!).\n\n## Contributing\n\nSee [CONTRIBUTING.md](https://github.com/BenConstable/phpspec-laravel/blob/master/CONTRIBUTING.md).\n\n## License\n\nMIT \u0026copy; Ben Constable. See [LICENSE](https://github.com/BenConstable/phpspec-laravel/blob/master/LICENSE) for more info.\n\n## Thanks\n\nThanks to...\n\n* [@obrignoni](https://github.com/obrignoni) for their great work in getting this extension working with Laravel 5\n* [@Sam-Burns](https://github.com/Sam-Burns) for their great work in getting this extension working with Phpspec v3 and v4\n* All of the [other contributors](https://github.com/BenConstable/phpspec-laravel/graphs/contributors) and to everyone that's\nreported issues and bugs with the project\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenconstable%2Fphpspec-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenconstable%2Fphpspec-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenconstable%2Fphpspec-laravel/lists"}