コード例 #1
0
 protected function makeTestCase($file, $name = '')
 {
     return Stub::make('\Codeception\Lib\DescriptiveTestCase', [
             'getReportFields' => ['file' => codecept_root_dir() . $file],
             'getName' => $name]
     );
 }
コード例 #2
0
ファイル: RestTest.php プロジェクト: vladislavl-hyuna/crmapp
 private function setStubResponse($response)
 {
     $connectionModule = Stub::make('\\Codeception\\Module\\UniversalFramework', ['_getResponseContent' => $response]);
     $this->module->_inject($connectionModule);
     $this->module->_initialize();
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
 }
コード例 #3
0
ファイル: StorageTest.php プロジェクト: zhikiri/storage
 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');
 }
コード例 #4
0
ファイル: DbTest.php プロジェクト: pfz/codeception
 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'));
 }
コード例 #5
0
 /**
  * @return Client
  */
 private static function create()
 {
     /** @var Delivery $delivery */
     $delivery = Stub::make('ArchiDelivery\\Delivery');
     $client = new Client($delivery);
     return $client;
 }
コード例 #6
0
ファイル: ScenarioCest.php プロジェクト: BatVane/Codeception
 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);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 private function setStubResponse($response)
 {
     $this->phpBrowser = Stub::make('\\Codeception\\Module\\PhpBrowser', ['_getResponseContent' => $response]);
     $this->module->_inject($this->phpBrowser);
     $this->module->_initialize();
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
 }
コード例 #9
0
 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, '*****@*****.**');
 }
コード例 #10
0
ファイル: DbTest.php プロジェクト: hendryguna/laravel-basic
 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'));
 }
コード例 #11
0
ファイル: ConverterCest.php プロジェクト: xobb/mconv
 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');
 }
コード例 #12
0
ファイル: DripTest.php プロジェクト: awesomemotive/drip
 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);
 }
コード例 #13
0
 public function testGetDocumentsIdsReturnsEmptyArray()
 {
     $query = Stub::make(SearchQuery::class, ['getFilters' => function () {
         return [];
     }]);
     $this->object = new ResultSet($query, []);
     $this->assertSame([], $this->object->getDocumentIds());
 }
コード例 #14
0
ファイル: StubTest.php プロジェクト: BatVane/Codeception
 public function testMake()
 {
     $dummy = Stub::make('DummyClass', array('goodByeWorld' => function () {
         return 'hello world';
     }));
     $this->assertEquals($this->dummy->helloWorld(), $dummy->helloWorld());
     $this->assertEquals("hello world", $dummy->goodByeWorld());
 }
コード例 #15
0
 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/');
 }
コード例 #16
0
ファイル: CsvParsingTest.php プロジェクト: tsurkanovm/test_mp
 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);
 }
コード例 #17
0
 /**
  * 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());
 }
 /**
  * @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();
 }
コード例 #19
0
 /**
  * @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);
 }
コード例 #20
0
 public function testBeforeInsert()
 {
     $stub_record = Stub::make('Comment', ['TABLE_NAME' => '123', 'beforeInsert' => Stub::once(function () {
         return false;
     })]);
     $stub_record->slug = 'testuser';
     $stub_record->title = 1;
     $result = $stub_record->save();
     $this->assertFalse($result);
 }
コード例 #21
0
ファイル: RestTest.php プロジェクト: Eli-TW/Codeception
 public function setUp()
 {
     $connector = new \Codeception\Lib\Connector\Universal();
     $connector->setIndex(\Codeception\Configuration::dataDir() . '/rest/index.php');
     $this->module = Stub::make('\\Codeception\\Module\\REST', ['getModules' => [new \Codeception\Module\PhpBrowser()]]);
     $this->module->_initialize();
     $this->module->_before(Stub::makeEmpty('\\Codeception\\TestCase\\Cest'));
     $this->module->client = $connector;
     $this->module->client->setServerParameters(array('SCRIPT_FILENAME' => 'index.php', 'SCRIPT_NAME' => 'index', 'SERVER_NAME' => 'localhost', 'SERVER_PROTOCOL' => 'http'));
 }
コード例 #22
0
 private function getProvider($type)
 {
     return Stub::make($this->getClientClass($type), ['getId' => $type, 'getUserAttributes' => function () use($type) {
         return $this->getClientAttributes($type);
     }, 'getAccessToken' => function () use($type) {
         return Stub::make(OAuthToken::class, ['getParams' => function () use($type) {
             return $this->getClientParamsToken($type);
         }]);
     }]);
 }
コード例 #23
0
ファイル: WebDebugCest.php プロジェクト: pfz/codeception
 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');
 }
コード例 #24
0
 public function testEncoder()
 {
     $encoder = new TestEncoder();
     $resource = Stub::make(Resource::class);
     $encoder->setFormatter(new TestFormatter());
     $encodedData = $encoder->encode($resource);
     $this->assertInstanceOf(\ObjectivePHP\Serializer\Encoder\EncoderInterface::class, $encoder);
     $this->assertInstanceOf(\ObjectivePHP\Serializer\Formatter\FormatterInterface::class, $encoder->getFormatter());
     $this->assertEquals(TestFormatter::class, get_class($encoder->getFormatter()));
     $this->assertEquals('encoded data', $encodedData);
 }
コード例 #25
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'));
 }
コード例 #26
0
 /**
  * @expectedException app\components\megaplanauth\MPAuthException
  * @expectedExceptionMessage Error requesting host
  */
 public function testAuthenticateFailedRequest()
 {
     $curlMock = Stub::make(new Curl(), ['post' => function () {
         throw new Exception();
     }]);
     $obj = new MegaplanAuth();
     $obj->url = 'https://some.url';
     $obj->curl = $curlMock;
     $obj->init();
     $result = $obj->authenticate('someuser', 'somepassword');
 }
コード例 #27
0
ファイル: Phalcon1.php プロジェクト: lenninsanchez/donadores
 /**
  *
  * @param \Symfony\Component\BrowserKit\Request $request
  * @return \Symfony\Component\BrowserKit\Response
  */
 public function doRequest($request)
 {
     $application = $this->getApplication();
     $di = $application->getDI();
     DI::reset();
     DI::setDefault($di);
     $_SERVER = array();
     foreach ($request->getServer() as $key => $value) {
         $_SERVER[strtoupper(str_replace('-', '_', $key))] = $value;
     }
     if (!$application instanceof \Phalcon\MVC\Application && !$application instanceof \Phalcon\MVC\Micro) {
         throw new \Exception('Unsupported application class');
     }
     $_COOKIE = $request->getCookies();
     $_FILES = $request->getFiles();
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     if (strtoupper($request->getMethod()) == 'GET') {
         $_GET = $request->getParameters();
     } else {
         $_POST = $request->getParameters();
     }
     $_REQUEST = $request->getParameters();
     $uri = str_replace('http://localhost', '', $request->getUri());
     $_SERVER['REQUEST_URI'] = $uri;
     $_GET['_url'] = strtok($uri, '?');
     $_SERVER['QUERY_STRING'] = http_build_query($_GET);
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $di['request'] = Stub::make($di->get('request'), array('getRawBody' => $request->getContent()));
     $response = $application->handle();
     $headers = $response->getHeaders();
     $status = (int) $headers->get('Status');
     $headersProperty = new \ReflectionProperty($headers, '_headers');
     $headersProperty->setAccessible(true);
     $headers = $headersProperty->getValue($headers);
     if (!is_array($headers)) {
         $headers = array();
     }
     $cookiesProperty = new \ReflectionProperty($di['cookies'], '_cookies');
     $cookiesProperty->setAccessible(true);
     $cookies = $cookiesProperty->getValue($di['cookies']);
     if (is_array($cookies)) {
         $restoredProperty = new \ReflectionProperty('\\Phalcon\\Http\\Cookie', '_restored');
         $restoredProperty->setAccessible(true);
         $valueProperty = new \ReflectionProperty('\\Phalcon\\Http\\Cookie', '_value');
         $valueProperty->setAccessible(true);
         foreach ($cookies as $name => $cookie) {
             if (!$restoredProperty->getValue($cookie)) {
                 $clientCookie = new Cookie($name, $valueProperty->getValue($cookie), $cookie->getExpiration(), $cookie->getPath(), $cookie->getDomain(), $cookie->getSecure(), $cookie->getHttpOnly());
                 $headers['Set-Cookie'][] = (string) $clientCookie;
             }
         }
     }
     return new Response($response->getContent(), $status ? $status : 200, $headers);
 }
コード例 #28
0
 public function setUp()
 {
     $this->module = new \Codeception\Module\Queue(make_container());
     $this->module->_setConfig($this->config);
     $this->module->_before(Stub::make('\\Codeception\\TestCase'));
     try {
         $this->module->clearQueue('default');
     } catch (\Pheanstalk_Exception_ConnectionException $e) {
         $this->markTestSkipped("Beanstalk is not running");
     }
 }
コード例 #29
0
 protected function _before()
 {
     //Can't be instantiated directly, because of specify ignored class
     $this->eventsManager = Stub::make('\\Symfony\\Component\\EventDispatcher\\EventDispatcher');
     $this->specifyConfig()->cloneOnly('eventsManager')->shallowClone();
     //Verify/Clean stubs should be isolated to each Specify block
     $this->afterSpecify(function () {
         $this->tester->verifyStubs();
         $this->tester->clearStubsToVerify();
     });
 }
コード例 #30
0
ファイル: DbTest.php プロジェクト: kansey/yii2albom
 public function testHaveAndSeeInDatabase()
 {
     self::$module->_before(\Codeception\Util\Stub::make('\\Codeception\\TestCase'));
     $user_id = self::$module->haveInDatabase('users', array('name' => 'john', 'email' => '*****@*****.**'));
     $group_id = self::$module->haveInDatabase('groups', array('name' => 'john', 'enabled' => false));
     $this->assertInternalType('integer', $user_id);
     self::$module->seeInDatabase('users', array('name' => 'john', 'email' => '*****@*****.**'));
     self::$module->dontSeeInDatabase('users', array('name' => 'john', 'email' => null));
     self::$module->_after(\Codeception\Util\Stub::make('\\Codeception\\TestCase'));
     self::$module->dontSeeInDatabase('users', array('name' => 'john'));
 }