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) { } }
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!')); }
public function testSaveSessionSnapshotsExcludeInvalidCookieDomains() { $this->notForPhantomJS(); $fakeWdOptions = Stub::make('\\Facebook\\WebDriver\\WebDriverOptions', ['getCookies' => Stub::atLeastOnce(function () { return [['name' => 'PHPSESSID', 'value' => '123456', 'path' => '/'], ['name' => '3rdParty', 'value' => '_value_', 'path' => '/', 'domain' => '.3rd-party.net']]; })]); $fakeWd = Stub::make(self::WEBDRIVER_CLASS, ['manage' => Stub::atLeastOnce(function () use($fakeWdOptions) { return $fakeWdOptions; })]); // Mock the WebDriverOptions::getCookies() method on the first call to introduce a 3rd-party cookie // which has to be ignored when saving a snapshot. $originalWebDriver = $this->module->webDriver; $this->module->webDriver = $fakeWd; $this->module->seeCookie('PHPSESSID'); $this->module->seeCookie('3rdParty'); $this->module->saveSessionSnapshot('login'); // Restore the original WebDriver $this->module->webDriver = $originalWebDriver; $this->webDriver->manage()->deleteAllCookies(); $this->module->dontSeeCookie('PHPSESSID'); $this->module->dontSeeCookie('3rdParty'); $this->module->loadSessionSnapshot('login'); $this->module->seeCookie('PHPSESSID'); $this->module->dontSeeCookie('3rdParty'); }
public function testRolenameIsUniqueSpecification() { $role = $this->prepareRole(); $this->specify("Set rolename for new role with existing rolename", function () use($role) { $roleRepository = Stub::makeEmpty('Inoplate\\Account\\Domain\\Repositories\\Role', ['findByName' => Stub::atLeastOnce(function () use($role) { return $role; })], $this); $specification = new AccountDomainSpecifications\RolenameIsUnique($roleRepository); expect("Specification is not satisfied", $specification->isSatisfiedBy($role->name()))->false(); }); $this->specify("Set rolename for existing role with another existing role's name", function () use($role) { $roleRepository = Stub::makeEmpty('Inoplate\\Account\\Domain\\Repositories\\Role', ['findByName' => Stub::atLeastOnce(function () use($role) { return $role; })], $this); $specification = new AccountDomainSpecifications\RolenameIsUnique($roleRepository, new AccountDomainModels\RoleId('56678')); expect("Specification is not satisfied", $specification->isSatisfiedBy($role->name()))->false(); }); $this->specify("Set rolename for existing role with same rolename", function () use($role) { $roleRepository = Stub::makeEmpty('Inoplate\\Account\\Domain\\Repositories\\Role', ['findByName' => Stub::atLeastOnce(function () use($role) { return $role; })], $this); $specification = new AccountDomainSpecifications\RolenameIsUnique($roleRepository, new AccountDomainModels\RoleId('789010')); expect("Specification is satisfied", $specification->isSatisfiedBy($role->name()))->true(); }); $this->specify("Set rolename for existing role with same rolename", function () use($role) { $roleRepository = Stub::makeEmpty('Inoplate\\Account\\Domain\\Repositories\\Role', ['findByName' => Stub::atLeastOnce(function () use($role) { return null; })], $this); $specification = new AccountDomainSpecifications\RolenameIsUnique($roleRepository); expect("Specification is satisfied", $specification->isSatisfiedBy($role->name()))->true(); }); }
public function testCanIgnoreTest() { $this->specify('testcase should be ignored if @ignoreProfiler class annotation met', function ($config, $options, $testCaseClass, $testCaseName, $timeout, $annotations, $expectedOutput) { $profiler = new Profiler($config, $options); $outputData = ''; $output = Stub::construct('\\Codeception\\Lib\\Console\\Output', [$options], ['write' => Stub::atLeastOnce(function ($messages) use(&$outputData) { $outputData .= $messages; })]); $this->tester->setProtectedProperty($profiler, 'output', $output); $this->eventsManager->addSubscriber($profiler); /** @var \PHPUnit_Framework_TestResult $testResult */ $testResult = Stub::makeEmpty('\\PHPUnit_Framework_TestResult'); /** @var \PHPUnit_Util_Printer $printer */ $printer = Stub::makeEmpty('\\PHPUnit_Util_Printer'); $testCase = $this->getMockBuilder('\\Codeception\\TestCase\\Test')->setMethods(['getAnnotations'])->setMockClassName($testCaseClass)->getMock(); $testCase->expects($this->exactly(2))->method('getAnnotations')->will($this->returnValue($annotations)); /** @var Test $testCase */ $testCase->setName($testCaseName); $this->eventsManager->dispatch(Events::TEST_BEFORE, new TestEvent($testCase)); usleep($timeout * 1000000.0); $this->eventsManager->dispatch(Events::TEST_END, new TestEvent($testCase)); $this->eventsManager->dispatch(Events::RESULT_PRINT_AFTER, new PrintResultEvent($testResult, $printer)); $this->assertProfileOutput($expectedOutput, $outputData); }, ['examples' => $this->getTestIgnoreAnnotationsData()]); }
/** * Test for testMapMethodResponse method success result * * ./vendor/bin/codecept run unit MapperTest.php:testMapMethodResponse * * @return void * * @covers \ITMH\Soap\Mapper::mapMethodResponse */ public function testMapMethodResponse() { $mapper = Stub::make('\\ITMH\\Soap\\Mapper', ['mapData' => Stub::atLeastOnce(), 'unwrapItem' => Stub::atLeastOnce()]); /* @var \ITMH\Soap\Mapper $mapper */ self::assertEquals([], $mapper->mapMethodResponse('method', [])); $mapper->setConfig(['method' => ['root' => 'ClassName']]); $mapper->mapMethodResponse('method', new stdClass()); $mapper->setConfig(['method' => ['class' => 'ClassName']]); $mapper->mapMethodResponse('method', new stdClass()); }