Пример #1
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 /**
  * 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
0
 public function testFindAll()
 {
     $stub_record = Stub::makeEmptyExcept('Comment', 'findAll', ['findBy' => Stub::once(function () {
         return true;
     })]);
     $stub_record->findAll();
 }
Пример #15
0
 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());
 }
 public function testSaveUpload()
 {
     $this->specify('test saveUpload', function () {
         $upload = Stub::make(UploadedFile::className(), ['name' => 'test.txt', 'saveAs' => Stub::once(function ($absoluteFilePath) {
             file_put_contents($absoluteFilePath, 'test content');
             return true;
         })], $this);
         $filePath = Yii::$app->uploads->saveUpload('test', $upload);
         $this->assertNotEmpty($filePath);
         $absoluteFilePath = Yii::$app->uploads->getAbsolutePath($filePath);
         $this->assertFileExists($absoluteFilePath);
         $this->assertEquals('test.txt', pathinfo($filePath, PATHINFO_BASENAME));
         $this->assertEquals('test content', file_get_contents($absoluteFilePath));
     });
 }