本文整理汇总了PHP中Codeception\Util\Stub::once方法的典型用法代码示例。如果您正苦于以下问题:PHP Stub::once方法的具体用法?PHP Stub::once怎么用?PHP Stub::once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Codeception\Util\Stub
的用法示例。
在下文中一共展示了Stub::once方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$backend = Stub::make('Codeception\\Util\\Mink', array('_saveScreenshot' => Stub::once()));
$backend->session = new \Codeception\Maybe();
$this->module = Stub::make('Codeception\\Module\\WebDebug', array('getModules' => array($backend)));
$this->module->_initialize();
$this->module->_before(Stub::make('Codeception\\TestCase\\Cept'));
}
示例2: testCreateSnapshotOnFail
public function testCreateSnapshotOnFail()
{
$module = Stub::construct(get_class($this->module), [make_container()], ['_savePageSource' => Stub::once(function ($filename) {
$this->assertEquals(codecept_log_dir('Codeception.Module.UniversalFramework.looks.like..test.fail.html'), $filename);
})]);
$module->amOnPage('/');
$cest = new \Codeception\Test\Cest($this->module, 'looks:like::test', 'demo1Cest.php');
$module->_failed($cest, new PHPUnit_Framework_AssertionFailedError());
}
示例3: testBuildingWithCustomService
public function testBuildingWithCustomService()
{
/* Given... (Fixture) */
$params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
$defaultBuilder = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\AbstractBuilderInterface', ['create' => Stub::never()]);
$userBuilder = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\BuilderInterface', ['create' => Stub::once()]);
$builder = new Builder();
$builder->addBuilder($defaultBuilder, Builder::DEFAULT_BUILDER)->addBuilder($userBuilder, 'users');
/* When... (Action) */
$entity = $builder->create($params, [], []);
/* Then... (Assertions) */
}
示例4: testDeletingWithCustomService
public function testDeletingWithCustomService()
{
/* Given... (Fixture) */
$params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
$entity = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
$defaultDeleter = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\DeleterInterface', ['create' => Stub::never()]);
$userDeleter = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\DeleterInterface', ['create' => Stub::once()]);
$deleter = new Deleter();
$deleter->addDeleter($defaultDeleter, Deleter::DEFAULT_DELETER)->addDeleter($userDeleter, 'users');
/* When... (Action) */
$entity = $deleter->delete($params, $entity);
/* Then... (Assertions) */
}
示例5: testDeletingWithCustomService
public function testDeletingWithCustomService()
{
/* Given... (Fixture) */
$params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryType' => 'users']);
$entity = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
$defaultMutator = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\MutatorInterface', ['create' => Stub::never()]);
$userMutator = Stub::makeEmpty('GoIntegro\\Hateoas\\Entity\\MutatorInterface', ['create' => Stub::once()]);
$mutator = new Mutator();
$mutator->addMutator($defaultMutator, Mutator::DEFAULT_MUTATOR)->addMutator($userMutator, 'users');
/* When... (Action) */
$entity = $mutator->update($params, $entity, [], []);
/* Then... (Assertions) */
}
示例6: testGettingMappingForEntity
public function testGettingMappingForEntity()
{
/* Given... (Fixture) */
$callOnce = Stub::once(function () {
return "The mapping.";
});
$entityManager = Stub::makeEmpty('Doctrine\\ORM\\EntityManagerInterface', ['getClassMetadata' => $callOnce]);
$metadataCache = new ArrayMetadataCache($entityManager);
/* When... (Action) */
$classMapping = $metadataCache->getMapping('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
$sameMapping = $metadataCache->getMapping('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
/* Then... (Assertions) */
$this->assertEquals('The mapping.', $classMapping);
$this->assertEquals($classMapping, $sameMapping);
}
示例7: testMe
public function testMe()
{
/** @var CacheItemPoolInterface $pool */
$pool = Stub::makeEmpty(CacheItemPoolInterface::class, ['getItem' => Stub::atLeastOnce(function () {
return Stub::makeEmpty(CacheItemInterface::class, ['isHit' => Stub::once(function () {
return false;
}), 'set' => Stub::once(function () {
}), 'get' => Stub::once(function () {
})]);
}), 'save' => Stub::exactly(2, function () {
})]);
$router = new \axisy\router\ContainerCacheable($pool, ['foo' => function () {
}, 'bar' => function () {
}]);
try {
$router->route('foo');
} catch (ErrorException $e) {
}
}
示例8: testBeforeTestProfiler
public function testBeforeTestProfiler()
{
$this->specify('profiler should invoke before test event', function ($config, $options, $testCaseClass, $testCaseName) {
/** @var Profiler $profiler */
$profiler = Stub::construct('\\Codeception\\Extension\\Profiler', [$config, $options], ['beforeTest' => Stub::once()]);
$this->eventsManager->addSubscriber($profiler);
/** @var Test $testCase */
$testCase = Stub::construct($testCaseClass, ['name' => $testCaseName]);
$this->eventsManager->dispatch(Events::TEST_BEFORE, new TestEvent($testCase));
$this->tester->addStubToVerify($profiler);
}, ['examples' => $this->getBeforeTestProfilerData()]);
$this->specify('profiler should be initialized', function ($config, $options, $testCaseClass, $testCaseName) {
$profiler = new Profiler($config, $options);
$this->eventsManager->addSubscriber($profiler);
/** @var Test $testCase */
$testCase = Stub::construct($testCaseClass, ['name' => $testCaseName]);
$this->eventsManager->dispatch(Events::TEST_BEFORE, new TestEvent($testCase));
$profileData = $this->tester->getProtectedProperty($profiler, 'profile');
$this->assertArrayHasKey(get_class($testCase), $profileData);
}, ['examples' => $this->getBeforeTestProfilerData()]);
}
示例9: testImport
public function testImport()
{
$this->specify("должен бросать исключение если файлы импорта не существуют", function () {
$er = new ExchangeRates();
$er->parse('fail.file');
}, ['throws' => 'PHPExcel_Reader_Exception']);
$this->specify("должен бросать исключение если не возможно определить какие курсы валют в нем содержатся", function () {
$er = new ExchangeRates();
$er->parse($this->data('wrong.xls'));
}, ['throws' => 'Matchish\\Exceptions\\ExchangeRatesParseException']);
$this->specify("должен правильно определять тип курсов в файле", function ($filename, $parserClassName) {
Stub::make($parserClassName, array('parse' => Stub::once(function () {
return [];
})));
$er = new ExchangeRates();
$er->parse($this->data($filename));
}, ['examples' => [['cash.xls', '\\Matchish\\ExchangeRatesCashParser'], ['card.xls', '\\Matchish\\ExchangeRatesCardParser']]]);
$this->specify("должен принимать массив имен файлов", function () {
$er = new ExchangeRates();
$er->parse([$this->data('cash.xls'), $this->data('card.xls')]);
});
}
示例10: matcherProvider
public static function matcherProvider()
{
return array(array(0, Stub::never()), array(1, Stub::once()), array(2, Stub::atLeastOnce()), array(3, Stub::exactly(3)), array(1, Stub::once(function () {
return true;
}), true), array(2, Stub::atLeastOnce(function () {
return array();
}), array()), array(1, Stub::exactly(1, function () {
return null;
}), null), array(1, Stub::exactly(1, function () {
return 'hello world!';
}), 'hello world!'));
}
示例11: testCreateTestScreenshotOnFail
public function testCreateTestScreenshotOnFail()
{
$test = Stub::make('\\Codeception\\TestCase\\Test', ['getName' => 'testLogin']);
$fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['takeScreenshot' => Stub::once(function ($filename) use($test) {
PHPUnit_Framework_Assert::assertEquals(codecept_log_dir(get_class($test) . '.testLogin.fail.png'), $filename);
}), 'getPageSource' => Stub::once(function () {
}), 'manage' => Stub::make('\\Facebook\\WebDriver\\WebDriverOptions', ['getAvailableLogTypes' => Stub::atLeastOnce(function () {
return [];
})])]);
$module = Stub::make(self::MODULE_CLASS, ['webDriver' => $fakeWd]);
$module->_failed($test, new PHPUnit_Framework_AssertionFailedError());
}
示例12: testCreateTestScreenshotOnFail
public function testCreateTestScreenshotOnFail()
{
$test = Stub::make('\\Codeception\\TestCase\\Test', ['getName' => 'testLogin']);
$fakeWd = Stub::make('\\RemoteWebDriver', ['takeScreenshot' => Stub::once(function ($filename) use($test) {
PHPUnit_Framework_Assert::assertEquals(codecept_log_dir(get_class($test) . '.testLogin.fail.png'), $filename);
}), 'getPageSource' => Stub::once(function () {
})]);
$this->module->webDriver = $fakeWd;
$this->module->_failed($test, new PHPUnit_Framework_AssertionFailedError());
}
示例13: testAsClass
/**
* Test for asClass method
*
* ./vendor/bin/codecept run unit SoapClientTest.php:testAsClass
*
* @return void
*
* @covers \ITMH\Soap\Client::asClass
*/
public function testAsClass()
{
$object = Stub::make(self::CLASS_NAME, ['mapObject' => Stub::once()], $this);
/* @var \ITMH\Soap\Client $object */
$data = ['root' => (object) ['foo' => 'bar']];
$object->asClass((object) $data);
}
示例14: testFindAll
public function testFindAll()
{
$stub_record = Stub::makeEmptyExcept('Comment', 'findAll', ['findBy' => Stub::once(function () {
return true;
})]);
$stub_record->findAll();
}
示例15: testCreateTestScreenshotOnFail
public function testCreateTestScreenshotOnFail()
{
$test = Stub::make('\\Codeception\\TestCase\\Test', ['getName' => 'testLogin']);
$wd = Stub::make('\\Codeception\\Module\\WebDriver', ['_saveScreenshot' => Stub::once(function ($actual) use($test) {
PHPUnit_Framework_Assert::assertEquals(codecept_log_dir(get_class($test) . '.testLogin.fail.png'), $actual);
})]);
$wd->_failed($test, new PHPUnit_Framework_AssertionFailedError());
}