public function testParsingASimpleRequest()
 {
     // Given...
     $repository = Stub::makeEmpty('Doctrine\\ORM\\EntityRepository', ['__call' => function ($name) {
         switch ($name) {
             case 'findOneById':
                 return self::AUTHOR_ENTITY;
                 break;
             case 'findById':
                 return self::COMMENT_ENTITIES;
                 break;
         }
     }]);
     $authorRelationship = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\ResourceRelationship');
     $commentsRelationship = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\ResourceRelationship');
     $relationships = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\ResourceRelationships', ['toOne' => ['author' => $authorRelationship], 'toMany' => ['comments' => $commentsRelationship]]);
     $metadata = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\ResourceMetadata', ['relationships' => $relationships, 'isToOneRelationship' => TRUE, 'isToManyRelationship' => TRUE]);
     $em = Stub::makeEmpty('Doctrine\\ORM\\EntityManagerInterface', ['getRepository' => $repository]);
     $mm = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\MetadataMinerInterface', ['mine' => $metadata]);
     $hydrant = new ResourceLinksHydrant($em, $mm);
     $params = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\Request\\Params', ['primaryClass' => "HateoasInc\\Bundle\\ExampleBundle\\Entity\\User"]);
     $resourceObject = ['content' => "Meh.", 'links' => ['author' => '5', 'comments' => ['45', '54', '67']]];
     // When...
     $hydrant->hydrate($params, $resourceObject);
     $expected = ['content' => "Meh.", 'links' => ['author' => self::AUTHOR_ENTITY, 'comments' => self::COMMENT_ENTITIES]];
     // Then...
     $this->assertEquals($expected, $resourceObject);
 }
Пример #2
0
 public function run(CodeGuy $I)
 {
     $I->wantTo('run steps from scenario');
     $I->haveStub($test = Stub::makeEmpty('\\Codeception\\TestCase\\Cept'));
     $I->haveStub($scenario = Stub::make('\\Codeception\\Scenario', array('test' => $test, 'steps' => Stub::factory('\\Codeception\\Step', 2))));
     $I->executeTestedMethodOn($scenario)->seeMethodInvoked($test, 'runStep')->seePropertyEquals($scenario, 'currentStep', 1);
 }
Пример #3
0
 protected function makeTest()
 {
     return Stub::makeEmpty(
         '\Codeception\TestCase\Cept',
         array('dispatcher' => Stub::makeEmpty('Symfony\Component\EventDispatcher\EventDispatcher'))
     );
 }
 public function testIsCloudflareRequest()
 {
     $tests = [[Stub::makeEmpty(RequestAdapter::class, ['getRemoteAddr' => '103.21.244.2', 'getHeaders' => ['cf-connecting-ip' => '127.0.0.1']]), true], [Stub::makeEmpty(RequestAdapter::class, ['getRemoteAddr' => '103.22.200.1', 'getHeaders' => ['cf-connecting-ip' => '127.0.0.1']]), true], [Stub::makeEmpty(RequestAdapter::class, ['getRemoteAddr' => '103.21.243.2', 'getHeaders' => ['cf-connecting-ip' => '127.0.0.1']]), false], [Stub::makeEmpty(RequestAdapter::class, ['getRemoteAddr' => '103.21.244.2', 'getHeaders' => ['custom-ip' => '127.0.0.1']]), false]];
     foreach ($tests as $testData) {
         list($request, $result) = $testData;
         $this->assertEquals($result, (new CloudflareDetector($this->ipAddresses, $request))->isCloudflareRequest());
     }
 }
Пример #5
0
 public function testBeforeHookResetsVariables()
 {
     $this->module->haveHttpHeader('Origin', 'http://www.example.com');
     $this->module->sendGET('/rest/user/');
     $this->assertEquals('http://www.example.com', $this->module->client->getServerParameter('HTTP_ORIGIN'));
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
     $this->assertNull($this->module->client->getServerParameter('HTTP_ORIGIN', null));
 }
Пример #6
0
 public function setUp()
 {
     $this->module = new \Codeception\Module\SOAP(make_container());
     $this->module->_setConfig(array('schema' => 'http://www.w3.org/2001/xml.xsd', 'endpoint' => 'http://codeception.com/api/wsdl'));
     $this->layout = \Codeception\Configuration::dataDir() . '/xml/layout.xml';
     $this->module->isFunctional = true;
     $this->module->_before(Stub::makeEmpty('\\Codeception\\Test\\Test'));
     $this->module->client = Stub::makeEmpty('\\Codeception\\Lib\\Connector\\Universal');
 }
Пример #7
0
 public function setUp()
 {
     $this->module = new \Codeception\Module\REST();
     $connector = new \Codeception\Util\Connector\Universal();
     $connector->setIndex(\Codeception\Configuration::dataDir() . '/rest/index.php');
     $this->module->client = $connector;
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
     $this->module->client->setServerParameters(array('SCRIPT_FILENAME' => 'index.php', 'SCRIPT_NAME' => 'index', 'SERVER_NAME' => 'localhost', 'SERVER_PROTOCOL' => 'http'));
 }
Пример #8
0
 public function testMakeEmptyMethodReplaced()
 {
     $dummy = Stub::makeEmpty('DummyClass', array('helloWorld' => function () {
         return 'good bye world';
     }));
     $this->assertTrue(method_exists($dummy, 'helloWorld'));
     $this->assertNotEquals($this->dummy->helloWorld(), $dummy->helloWorld());
     $this->assertEquals($dummy->helloWorld(), 'good bye world');
 }
Пример #9
0
 public function setUp()
 {
     $this->dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
     $settings = \Codeception\Configuration::$defaultSuiteSettings;
     $settings['class_name'] = 'CodeGuy';
     $this->suiteman = new \Codeception\SuiteManager($this->dispatcher, 'suite', $settings);
     $printer = \Codeception\Util\Stub::makeEmpty('PHPUnit_TextUI_ResultPrinter');
     $this->runner = new \Codeception\PHPUnit\Runner();
     $this->runner->setPrinter($printer);
 }
 public function testCheckingFreshnessOfCache()
 {
     // Given...
     $kernel = Stub::makeEmpty('Symfony\\Component\\HttpKernel\\KernelInterface', ['isDebug' => TRUE]);
     $cache = new RamlDocSymfonyCache($kernel);
     // When...
     $isFresh = $cache->isFresh();
     // Then...
     $this->assertFalse($isFresh);
 }
Пример #11
0
 public function generateFilename(CodeGuy $I)
 {
     $I->haveFakeClass($stub = Stub::make($this->class, array('test' => Stub::makeEmpty('\\Codeception\\TestCase\\Cept', array('getFileName' => function () {
         return 'testtest';
     })))));
     $I->executeTestedMethod($stub);
     $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 1');
     $I->executeTestedMethod($stub, 'mytest');
     $I->seeResultEquals(\Codeception\Configuration::logDir() . 'debug' . DIRECTORY_SEPARATOR . 'testtest - 2 - mytest');
 }
Пример #12
0
 public function setUp()
 {
     $this->module = new \Codeception\Module\Queue(make_container());
     $this->module->_setConfig($this->config);
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase'));
     try {
         $this->module->clearQueue('default');
     } catch (\Pheanstalk_Exception_ConnectionException $e) {
         $this->markTestSkipped("Beanstalk is not running");
     }
 }
Пример #13
0
 public function testBeforeHookResetsVariables()
 {
     $this->module->haveHttpHeader('Origin', 'http://www.example.com');
     $this->module->sendGET('/rest/user/');
     $server = $this->module->client->getInternalRequest()->getServer();
     $this->assertArrayHasKey('HTTP_ORIGIN', $server);
     $this->module->_before(Stub::makeEmpty('\\Codeception\\Test\\Test'));
     $this->module->sendGET('/rest/user/');
     $server = $this->module->client->getInternalRequest()->getServer();
     $this->assertArrayNotHasKey('HTTP_ORIGIN', $server);
 }
Пример #14
0
 public function setUp()
 {
     $this->phpBrowser = new \Codeception\Module\PhpBrowser();
     $url = 'http://localhost:8010';
     $this->phpBrowser->_setConfig(array('url' => $url));
     $this->phpBrowser->_initialize();
     $this->module = Stub::make('\\Codeception\\Module\\REST', ['getModules' => [$this->phpBrowser]]);
     $this->module->_initialize();
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
     $this->phpBrowser->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
 }
Пример #15
0
 /**
  * @depends testNavigatingARaml
  */
 public function testFindingInlineBodySchema()
 {
     /* Given... (Fixture) */
     $jsonCoder = Stub::makeEmpty('GoIntegro\\Json\\JsonCoder');
     $ramlDoc = Stub::makeEmpty('GoIntegro\\Raml\\RamlDoc', ['rawRaml' => Yaml::parse(__DIR__ . self::INLINE_BODY_SCHEMA_RAML), 'schemas' => Stub::makeEmpty('GoIntegro\\Raml\\Root\\MapCollection')]);
     $navigator = new DocNavigator($ramlDoc, $jsonCoder);
     /* When... (Action) */
     $schema = $navigator->findRequestSchema(RamlSpec::HTTP_POST, '/some-resources');
     /* Then... (Assertions) */
     $this->assertEquals(self::INLINE_BODY_SCHEMA, $schema);
 }
Пример #16
0
 public function testParsingRamlDoc()
 {
     /* Given... (Fixture) */
     $mapCollectionParser = Stub::makeEmpty('GoIntegro\\Raml\\MapCollectionParser');
     $docExpander = Stub::makeEmpty('GoIntegro\\Raml\\DocExpander');
     $parser = new DocParser($mapCollectionParser, $docExpander);
     /* When... (Action) */
     $ramlDoc = $parser->parse(__DIR__ . self::RAML_PATH);
     /* Then... (Assertions) */
     $this->assertInstanceOf('GoIntegro\\Raml\\RamlDoc', $ramlDoc);
 }
Пример #17
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) */
 }
Пример #18
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) */
 }
Пример #19
0
 public function setUp()
 {
     $this->testCase = Stub::makeEmpty('\\Codeception\\TestCase');
     $module = new \Codeception\Module\Dbh(make_container());
     try {
         $driver = Driver::create($this->config['dsn'], $this->config['user'], $this->config['password']);
         $module::$dbh = $driver->getDbh();
     } catch (\PDOException $e) {
         $this->markTestSkipped('Coudn\'t establish connection to database');
         return;
     }
     $this->module = $module;
 }
Пример #20
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) */
 }
 private function getDbStub()
 {
     return Stub::makeEmpty('Phalcon\\Db\\Adapter\\Pdo', array('fetchOne' => function ($sql, $fetchMode, $params) {
         if ($sql == 'SELECT COUNT(*) as count FROM users WHERE login = ?') {
             if ($params[0] == 'login_taken') {
                 return array('count' => 1);
             } else {
                 return array('count' => 0);
             }
         }
         return null;
     }));
 }
Пример #22
0
 public function testParsingMapCollection()
 {
     /* Given... (Fixture) */
     $jsonCoder = Stub::makeEmpty('GoIntegro\\Json\\JsonCoder');
     $path = __DIR__ . self::RAML_PATH;
     $ramlDoc = Stub::makeEmpty('GoIntegro\\Raml\\RamlDoc', ['fileDir' => dirname($path), 'rawRaml' => Yaml::parse($path)]);
     $raw = ['!include some-traits.yml', ['secured' => '!include some-trait.yml'], ['paged' => ['queryParameters' => ['start' => ['type' => 'number']]]], ['searchable' => ['queryParameters' => ['query' => ['type' => 'string']]]]];
     $parser = new MapCollectionParser($jsonCoder);
     /* When... (Action) */
     $mapCollection = $parser->parse('traits', $raw, $ramlDoc);
     /* Then... (Assertions) */
     $this->assertInstanceOf('GoIntegro\\Raml\\Root\\MapCollection', $mapCollection);
 }
Пример #23
0
    public function setUp() {
        $this->phpBrowser = new \Codeception\Module\PhpBrowser();
        $url = 'http://localhost:8010';
        $this->phpBrowser->_setConfig(array('url' => $url));
        $this->phpBrowser->_initialize();
        $this->phpBrowser->_before(Stub::makeEmpty('\Codeception\TestCase\Cest'));

        $this->module = new \Codeception\Module\REST();
        $this->module->_initialize();
        $this->module->client = $this->phpBrowser->client;
        $this->module->_before(Stub::makeEmpty('\Codeception\TestCase\Cest'));

    }
Пример #24
0
 public function testReconnectOption()
 {
     $testCase1 = \Codeception\Util\Stub::makeEmpty('\\Codeception\\TestInterface');
     $testCase2 = \Codeception\Util\Stub::makeEmpty('\\Codeception\\TestInterface');
     self::$module->_reconfigure(['reconnect' => true]);
     $this->assertNotNull(self::$module->driver, 'driver is null before test');
     $this->assertNotNull(self::$module->dbh, 'dbh is null before test');
     self::$module->_after($testCase1);
     $this->assertNull(self::$module->driver, 'driver is not unset by _after');
     $this->assertNull(self::$module->dbh, 'dbh is not unset by _after');
     self::$module->_before($testCase2);
     $this->assertNotNull(self::$module->driver, 'driver is not set by _before');
     $this->assertNotNull(self::$module->dbh, 'dbh is not set by _before');
     self::$module->_reconfigure(['reconnect' => false]);
 }
Пример #25
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);
 }
Пример #26
0
 private function getDbStub()
 {
     codecept_debug('getDbStub');
     return Stub::makeEmpty('Phalcon\\Db\\Adapter\\Pdo', ['fetchOne' => function ($sql, $fetchMode, $params) {
         if ($sql !== 'SELECT COUNT(*) AS count FROM "users" WHERE "login" = ? AND "id" != ?' && $sql !== 'SELECT COUNT(*) AS count FROM "users" WHERE "login" = ?') {
             return null;
         }
         if ($params[0] == 'login_taken') {
             return ['count' => 1];
         } else {
             return ['count' => 0];
         }
     }, 'escapeIdentifier' => function ($identifier) {
         return "\"{$identifier}\"";
     }]);
 }
Пример #27
0
 public function testExpandingRamlDoc()
 {
     /* Given... (Fixture) */
     $collection = Stub::makeEmpty('GoIntegro\\Raml\\Root\\MapCollection', ['has' => TRUE, 'get' => function ($name) {
         return Stub::makeEmpty('GoIntegro\\Raml\\Root\\ResourceType', ['apply' => [$name => TRUE]]);
     }]);
     $ramlDoc = Stub::makeEmpty('GoIntegro\\Raml\\RamlDoc', ['rawRaml' => Yaml::parse(__DIR__ . self::RAML_PATH), 'resourceTypes' => $collection, 'traits' => $collection]);
     $expander = new DocExpander();
     /* When... (Action) */
     $expander = $expander->expand($ramlDoc);
     /* Then... (Assertions) */
     $this->assertInstanceOf('GoIntegro\\Raml\\DocExpander', $expander);
     $this->assertTrue($ramlDoc->rawRaml['/some-resources']['get']['searchable']);
     $this->assertTrue($ramlDoc->rawRaml['/some-other-resources']['get']['secured']);
     $this->assertTrue($ramlDoc->rawRaml['/some-other-resources']['post']['secured']);
     $this->assertTrue($ramlDoc->rawRaml['/some-other-resources']['/{some-resources-ids}']['collection']);
 }
 /**
  * @param integer $amount
  * @param integer $offset
  * @return \GoIntegro\Hateoas\JsonApi\ResourceCollection
  */
 private static function createResourcesMock($amount, $offset = 0)
 {
     $metadata = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\ResourceMetadata', ['type' => self::RESOURCE_TYPE, 'subtype' => self::RESOURCE_TYPE, 'fields' => []]);
     $resources = [];
     for ($i = 0; $i < $amount; ++$i) {
         $resources[] = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\EntityResource', ['id' => (string) $offset, 'getMetadata' => function () use($metadata) {
             return $metadata;
         }]);
         ++$offset;
     }
     $collection = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceCollection', ['getMetadata' => function () use($metadata) {
         return $metadata;
     }, 'getIterator' => function () use($resources) {
         return new \ArrayIterator($resources);
     }, 'count' => function () use($resources) {
         return count($resources);
     }]);
     return $collection;
 }
Пример #29
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) {
     }
 }
Пример #30
0
 public function testAddingAResource()
 {
     /* Given... (Fixture) */
     $entity = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\ResourceEntityInterface');
     $entityResource = Stub::makeEmpty('GoIntegro\\Hateoas\\JsonApi\\EntityResource', ['entity' => $entity]);
     $classReflection = Stub::makeEmpty('ReflectionClass', ['getName' => function () {
         return 'GoIntegro\\Entity\\User';
     }]);
     $metadataCache = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Entity\\MetadataCache', ['getReflection' => function ($object) use($entity, $classReflection) {
         if ($object instanceof ResourceEntityInterface) {
             return $classReflection;
         }
     }]);
     $metadataMiner = Stub::makeEmpty('GoIntegro\\Hateoas\\Metadata\\Resource\\MetadataMinerInterface');
     $serviceContainer = Stub::makeEmpty('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $resourceCache = new ArrayResourceCache($metadataCache, $metadataMiner, $serviceContainer);
     /* When... (Action) */
     $sameCache = $resourceCache->addResource($entityResource);
     $sameResource = $resourceCache->getResourceForEntity($entity);
     /* Then... (Assertions) */
     $this->assertSame($resourceCache, $sameCache);
     $this->assertSame($entityResource, $sameResource);
 }