在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):BenConstable/phpspec-laravel开源软件地址(OpenSource Url):https://github.com/BenConstable/phpspec-laravel开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):phpspec Laravel ExtensionVersionsDepending on the version of Laravel and/or Phpspec you're using, you'll want to make sure that you're using the version of this package that's right for you. Use the table below to pick the right one.
InstallationInstall the package with composer:
then add this to your extensions:
PhpSpec\Laravel\Extension\LaravelExtension: ~ You can take a look at Why this extension?This extension provides you with a bootstrapped Laravel environment when writing your phpspec tests. It allows you to make use of some of the nice features that Laravel provides, like class aliases and helper functions, without being hindered by your testing framework. This extension is not a swap-in replacement for Laravel's built in PHPUnit setup. If you'd like integration and/or functional tests, please use that, Behat, or Codeception. ConfigurationTesting environmentBy default, the extension bootstraps Laravel in the extensions:
PhpSpec\Laravel\Extension\LaravelExtension:
testing_environment: "production" in your App bootstrap pathBy default, the extension will bootstrap your app by looking for You can manually specify the path to the bootstrap file if you're using a non-standard installation, like so: extensions:
PhpSpec\Laravel\Extension\LaravelExtension:
framework_path: "/non/standard/laravel/setup/app.php" You can specify either an absolute path (use leading slash), or a path relative
to the UsageTesting without LaravelIf you're not using any code specific to the Laravel environment, then you don't need to do anything differently. Just write your phpspec tests as normal! Testing with LaravelIf you want to take advantage of Laravel's aliases, or use some of its
helper functions, extend your specs
from For example, this class uses an alias: <?php
namespace App;
use Inspiring;
class MyInspiring extends Inspiring
{
public function quoteBackwards()
{
return strrev(parent::quote());
}
} and without extending from <?php
namespace spec\App;
use PhpSpec\ObjectBehavior;
class MyInspiringSpec extends ObjectBehavior
{
function it_inspires_backwards()
{
$this->quoteBackwards()->shouldBeString();
}
} you'll get <?php
namespace spec\App;
use PhpSpec\Laravel\LaravelObjectBehavior;
class MyInspiringSpec extends LaravelObjectBehavior
{
function it_inspires_backwards()
{
$this->quoteBackwards()->shouldBeString();
}
} you'll get and this class uses a helper function: <?php
namespace App;
class MyEncryptor
{
public function encrypt($arg)
{
return bcrypt($arg);
}
} and without extending from <?php
namespace spec\App;
use PhpSpec\ObjectBehavior;
class MyEncryptor extends ObjectBehavior
{
function it_encrypts_a_string()
{
$this->encrypt()->shouldBeString();
}
} you'll get <?php
namespace spec\App;
use PhpSpec\Laravel\LaravelObjectBehavior;
class MyEncryptor extends LaravelObjectBehavior
{
function it_encrypts_a_string()
{
$this->encrypt()->shouldBeString();
}
} you'll get Accessing the IoC containerIf you need to access the Service Container
in your specs, just use the Learning more about phpspec and LaravelLaracasts has some great guides on phpspec and Laravel. 'Laravel, phpspec and refactoring' is a good starting point; it shows how you should use phpspec with Laravel, and covers the basics of writing tests (and it's free!). ContributingSee CONTRIBUTING.md. LicenseMIT © Ben Constable. See LICENSE for more info. ThanksThanks to...
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论