在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):laracasts/Behat-Laravel-Extension开源软件地址(OpenSource Url):https://github.com/laracasts/Behat-Laravel-Extension开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):This extension offers an incredibly simple (and fast) way to begin testing and driving your Laravel applications with Behat. Some benefits include:
To get started, you only need to follow a few steps:
1. Install DependenciesAs always, we need to pull in some dependencies through Composer.
This will give us access to Behat, Mink, and, of course, the Laravel extension. 2. Create the Behat.yml Configuration FileNext, within your project root, create a
Here, is where we reference the Laravel extension, and tell Behat to use it as our default session. You may pass an optional parameter, This file should, like the standard 3. Setting up FeatureContextRun, from the root of your app
It should set
At this point you should set it to extend MinkContext.
4. Write Some FeaturesYou're all set to go! Start writing some features. If you want a quick dummy example to get you started, refer to this project.
Feature Context TraitsAs a convenience, this package also includes a number of traits to streamline common tasks, such as migrating your database, or using database transactions, or even testing mail. MigratorOften, you'll find yourself in situations where you want to migrate your test database before a scenario. Easy! Just pull in the // ...
use Laracasts\Behat\Context\Migrator;
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
use Migrator;
} That's it! The trait will do the rest. Before each scenario runs, if your database needs to be migrated, it will be! Database TransactionsOn the other hand, you might prefer to run all of your tests through database transactions. You'll get a nice speed boost out of the deal, as your data will never actually be saved to the database. To take advantage of this, once again, pull in the // ...
use Laracasts\Behat\Context\DatabaseTransactions;
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
use DatabaseTransactions;
} Once you pull in this trait, before each scenario runs, it'll begin a new transaction. And when the scenario completes, we'll roll it back for you. Service: MailTrapEspecially when functional testing, it can be beneficial to test your mail against a real test server (rather than mocking it out, and hoping that things were formatted correctly). If you're a fan of MailTrap (highly recommended), this extension can help you! If you haven't already, create a quick account (free) and inbox at MailTrap.io. Next, update either your 'mailtrap' => [
'secret' => 'YOUR API KEY',
'default_inbox' => 'ID OF THE MAILTRAP INBOX YOU CREATED'
] That should do it! Now, just pull in the trait, and you're ready to go! Let me show you: <?php
// ...
use Laracasts\Behat\Context\Services\MailTrap;
use PHPUnit_Framework_Assert as PHPUnit;
class DmcaContext extends MinkContext implements SnippetAcceptingContext
{
use MailTrap;
/**
* @Then an email should be sent to YouTube
*/
public function anEmailShouldBeSentToYoutube()
{
$lastEmail = $this->fetchInbox()[0];
$stub = file_get_contents(__DIR__ . '/../stubs/dmca-complete.txt');
PHPUnit::assertEquals('DMCA Notice', $lastEmail['subject']);
PHPUnit::assertContains($stub, $lastEmail['text_body']);
}
} Notice that call to $lastEmail = $this->fetchInbox()[0]; If working along, you can dump that variable to see all of the various fields that you may write assertions against. In the example above, we're ensuring that the subject was set correctly, and the body of the email matches a stub that we've created. Even better, after each scenario completes, we'll go ahead and empty out your MailTrap inbox for convenience by adding the
FAQI'm getting a "PHP Fatal error: Maximum function nesting level of '100' reached, aborting!" error.Sounds like you're using Xdebug. Increase the max nesting level. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论