public function testCreateInstanceWithRingPHP() { $log = $trace = Stub::make('\\Monolog\\Logger', []); $ringphp_handler = Stub::make('WyriHaximus\\React\\RingPHP\\HttpClientAdapter'); $connection = new Guzzle5Connection(['host' => 'localhost', 'port' => 9200, 'ringphp_handler' => $ringphp_handler], null, $log, $trace); $this->assertInstanceOf('Iwai\\Elasticsearch\\Guzzle5Connection', $connection); }
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); }
protected function makeTest() { return Stub::makeEmpty( '\Codeception\TestCase\Cept', array('dispatcher' => Stub::makeEmpty('Symfony\Component\EventDispatcher\EventDispatcher')) ); }
public function testHaveAndSeeInDatabase() { $this->module->haveInDatabase('users', array('name' => 'john')); $this->module->seeInDatabase('users', array('name' => 'john')); $this->module->_before(\Codeception\Util\Stub::make('\\Codeception\\TestCase')); $this->module->dontSeeInDatabase('users', array('name' => 'john')); }
protected function makeTestCase($file, $name = '') { return Stub::make('\Codeception\Lib\DescriptiveTestCase', [ 'getReportFields' => ['file' => codecept_root_dir() . $file], 'getName' => $name] ); }
public function constructDumbGenericCLI($params = array(), $override = array()) { $defaultParams = array('namespace' => 'DumbExtension', 'type' => 'cli'); $defaultOverride = array(); $instance = Stub::construct('\\Alledia\\Framework\\Joomla\\Extension\\Generic', array_merge($defaultParams, $params), array_merge($defaultOverride, $override)); return $instance; }
protected function makeCommand($className, $saved = true, $extraMethods = []) { if (!$this->config) { $this->config = []; } $self = $this; $mockedMethods = ['save' => function ($file, $output) use($self, $saved) { if (!$saved) { return false; } $self->filename = $file; $self->content = $output; $self->log[] = ['filename' => $file, 'content' => $output]; $self->saved[$file] = $output; return true; }, 'getGlobalConfig' => function () use($self) { return $self->config; }, 'getSuiteConfig' => function () use($self) { return $self->config; }, 'buildPath' => function ($path, $testName) { $path = rtrim($path, DIRECTORY_SEPARATOR); $testName = str_replace(['/', '\\'], [DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], $testName); return pathinfo($path . DIRECTORY_SEPARATOR . $testName, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR; }, 'getSuites' => function () { return ['shire']; }, 'getApplication' => function () { return new \Codeception\Util\Maybe(); }]; $mockedMethods = array_merge($mockedMethods, $extraMethods); $this->command = Stub::construct($className, [$this->commandName], $mockedMethods); }
public function testDispatchMethod() { $separator = Storage::$separator; $method = self::getPrivateMethod('dispatch'); $structure = $method->invoke(Stub::make(self::$class), "base{$separator}inner{$separator}key"); $this->assertEquals($structure, array('base', 'inner', 'key'), 'Parsing of the passed path is failed'); }
/** * @return Client */ private static function create() { /** @var Delivery $delivery */ $delivery = Stub::make('ArchiDelivery\\Delivery'); $client = new Client($delivery); return $client; }
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); }
public function testGetHttpClient() { /** @var \AwesomeMotive\Drip\Token $token */ $token = Stub::make("\\AwesomeMotive\\Drip\\Token", ['get_accessToken' => '1234']); $this->drip->set_token($token); $client = $this->drip->get_httpClient(); $this->assertInstanceOf("\\GuzzleHttp\\Client", $client); }
public function test_unserialize_real_serialized_object() { $user = Stub::make('StdClass', array('username' => 'username', 'email' => '*****@*****.**')); $so = new SerializedObject(serialize($user)); $result = $so->unserialize(); $this->assertEquals($result->username, 'username'); $this->assertEquals($result->email, '*****@*****.**'); }
public function _before() { //echo "ENV:".getenv('thisTestRun_testIncludePath'); //die(); //chdir(getenv('thisTestRun_testIncludePath')); //require_once "system/classes/Config.php"; $this->config = Stub::construct('Config'); }
public function testDelete() { $file = Stub::construct('\\Uploads\\models\\UploadedFile', ['filePath' => $this->baseTestFileString], ['getOwnerClass' => 'Test', 'getOwnerId' => 2, 'getDirToUpload' => yii::getAlias(implode(DIRECTORY_SEPARATOR, ['@backend', 'web', 'upload']))]); $file->save(); $filePath = $file->fullPath; $file->delete(); $this->assertFalse(file_exists($filePath)); }
public function testHaveAndSeeInDatabase() { $user_id = $this->module->haveInDatabase('users', array('name' => 'john', 'email' => '*****@*****.**')); $this->assertInternalType('integer', $user_id); $this->module->seeInDatabase('users', array('name' => 'john', 'email' => '*****@*****.**')); $this->module->_after(\Codeception\Util\Stub::make('\Codeception\TestCase')); $this->module->dontSeeInDatabase('users', array('name' => 'john')); }
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()); } }
public function convertWithException(\CodeGuy $I) { $I->wantTo("test if converting of different measure types fails."); $I->haveStub($converter = Stub::make($this->class)); $I->amTestingMethod('\\Measure\\Converter.convert'); $I->executeTestedMethodOn($converter, 1, 'liter', 'kg'); $I->seeExceptionThrown('\\ErrorException'); }
public function testGetDocumentsIdsReturnsEmptyArray() { $query = Stub::make(SearchQuery::class, ['getFilters' => function () { return []; }]); $this->object = new ResultSet($query, []); $this->assertSame([], $this->object->getDocumentIds()); }
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)); }
/** * When running multiple environments, getClassesFromFile() method in SuiteManager is called once for each env. * See \Codeception\Codecept::runSuite() - for each env new SuiteManager is created and tests loaded. * Make sure that calling getClassesFromFile() multiple times will always return the same classes. * * @group core */ public function testAddCestWithEnv() { $file = \Codeception\Configuration::dataDir() . 'SimpleCestWithNamespace.php'; $this->suiteman->addCest($file); $this->assertEquals(3, $this->suiteman->getSuite()->count()); $newSuiteMan = Stub::make('\\Codeception\\SuiteManager', array('dispatcher' => $this->dispatcher, 'suite' => new PHPUnit_Framework_TestSuite(), 'settings' => array('bootstrap' => false, 'class_name' => 'CodeGuy', 'namespace' => ''))); $newSuiteMan->addCest($file); $this->assertEquals(3, $newSuiteMan->getSuite()->count()); }
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()); }
protected function setUp() { $this->moduleContainer = new ModuleContainer(Stub::make('Codeception\\Lib\\Di'), []); $this->moduleContainer->create('EmulateModuleHelper'); $this->modules = $this->moduleContainer->all(); $this->actions = $this->moduleContainer->getActions(); $this->makeCommand('\\Codeception\\Command\\GenerateScenarios'); $this->config = array('paths' => array('tests' => 'tests/data/claypit/tests/', 'data' => '_data'), 'class_name' => 'DumbGuy', 'path' => 'tests/data/claypit/tests/dummy/'); }
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'); }
/** * @expectedException \GuzzleHttp\Exception\ConnectException */ public function testFailConnection() { $log = $trace = Stub::make('\\Monolog\\Logger', []); $connection = new Guzzle5Connection(['host' => 'localhost5', 'port' => 9200], null, $log, $trace); /** @var \Iwai\Elasticsearch\FutureResult $response */ $response = $connection->performRequest('GET', '/'); $this->assertInstanceOf('Iwai\\Elasticsearch\\FutureResult', $response); $response->wait(); }
public function parseFileByOptions($options) { self::$parser_handler->setConfiguration($options); $csv_parser = Stub::make(new YiiMultiparser(), ['parserHandler' => self::$parser_handler]); if (!$csv_parser) { self::markTestSkipped('Parser handler do not initialized.'); } self::$data = $csv_parser->parse(self::$file_path); }
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')); }
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); }
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); }
/** * @test */ public function criarUmPedidoSalvarERetornarSucesso() { // Arrange //$pedidoServicos = new PedidoServicos(); $pedidoServicos = \Codeception\Util\Stub::make('PedidoServicos', ['salvar' => 'Sucesso']); // Act $resultado = $pedidoServicos->salvar($this->pedido); // Assert $this->assertEquals("Sucesso", $resultado); }
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'); }