Exemple #1
0
    public function setUp()
    {
        $this->pdo = Phake::partialMock('PDO', $_ENV['MySQL_Store_DSN'], $_ENV['MySQL_Store_User'], $_ENV['MySQL_Store_Password']);
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->pdo->exec('SET foreign_key_checks = 0');
        $this->pdo->exec('CREATE DATABASE IF NOT EXISTS `machinist_test`;');
        $this->pdo->exec('USE `machinist_test`;');
        $this->pdo->exec('DROP TABLE IF EXISTS `stuff`;');
        $this->pdo->exec('create table `stuff` ( `id` INTEGER PRIMARY KEY AUTO_INCREMENT, `name` varchar(100) );');
        $this->pdo->exec('DROP TABLE IF EXISTS `some_stuff`;');
        $this->pdo->exec('CREATE TABLE `some_stuff` (
												`some_id` int(10) unsigned NOT NULL,
												`stuff_id` int(10) unsigned NOT NULL,
												`name` VARCHAR(100),
												PRIMARY KEY (`some_id`,`stuff_id`));');
        $this->pdo->exec('DROP TABLE IF EXISTS `group`;');
        $this->pdo->exec('create table `group` ( `id` INTEGER PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(255));');
        $this->pdo->exec('DROP TABLE IF EXISTS `nopk`;');
        $this->pdo->exec('create table `nopk` ( `id` INTEGER, `name` VARCHAR(255));');
        $this->pdo->exec('DROP TABLE IF EXISTS `fkey`;');
        $this->pdo->exec('CREATE TABLE `fkey` 
                                        ( `id` int(11) NOT NULL AUTO_INCREMENT,
                                          `stuff_id` int(11),
                                          PRIMARY KEY (`id`),
                                          KEY `IDX_1` (`stuff_id`),
                                          CONSTRAINT `FK_1` FOREIGN KEY (`stuff_id`) REFERENCES `stuff` (`id`)
                                        ) ENGINE=InnoDB');
        $this->pdo->exec('SET foreign_key_checks = 1');
        $this->driver = SqlStore::fromPdo($this->pdo);
    }
Exemple #2
0
 public function setUp()
 {
     $this->connection = \Phake::mock('\\mysqli');
     $this->statement = \Phake::mock('\\Hoimi\\Session\\StatementDummy');
     $this->target = \Phake::partialMock('Hoimi\\Session\\DatabaseDriver', new Config());
     $this->target->setConnection($this->connection);
 }
 /**
  * For some reason setUp nor setUpBeforeClass would create the requested object
  *
  * @return Screen
  */
 protected function getScreen()
 {
     if (empty($this->screen) === true) {
         $this->screen = Phake::partialMock('Arjf\\Devices\\Handheld\\Apple\\Screen', 320, 480);
     }
     return $this->screen;
 }
 protected function callProtectedMusicAPI($call_fn, $expected_url_extension, $expected_params = [], $sample_response = null)
 {
     if ($sample_response === null) {
         $sample_response = ['foo' => 'bar'];
     }
     $generator = new Generator();
     // set up the mock to check headers generated
     $tokenly_api = Phake::partialMock('Tokenly\\APIClient\\TokenlyAPI', 'https://127.0.0.1/api/v1', $generator, 'MY_CLIENT_ID', 'MY_CLIENT_SECRET');
     $called_vars = [];
     Phake::when($tokenly_api)->callRequest(Phake::anyParameters())->thenReturnCallback(function ($url, $headers, $request_params, $method, $request_options) use($sample_response, &$called_vars) {
         $called_vars = [];
         $response = new Requests_Response();
         $response->body = json_encode($sample_response);
         $called_vars['headers'] = $headers;
         $called_vars['url'] = $url;
         $called_vars['params'] = $request_params;
         return $response;
     });
     $music_api = new MusicAPI($tokenly_api);
     // check API call
     $result = $call_fn($music_api);
     PHPUnit::assertEquals($sample_response, $result);
     // check called URL
     PHPUnit::assertEquals('https://127.0.0.1/api/v1/' . $expected_url_extension, $called_vars['url']);
     // check headers
     $headers_generated = $called_vars['headers'];
     PHPUnit::assertNotEmpty($headers_generated);
     $nonce = $headers_generated['X-TOKENLY-AUTH-NONCE'];
     PHPUnit::assertGreaterThanOrEqual(time(), $nonce);
     PHPUnit::assertEquals('MY_CLIENT_ID', $headers_generated['X-TOKENLY-AUTH-API-TOKEN']);
     $expected_signature = $this->expectedSignature($nonce, 'https://127.0.0.1/api/v1/' . $expected_url_extension, $expected_params);
     PHPUnit::assertEquals($expected_signature, $headers_generated['X-TOKENLY-AUTH-SIGNATURE']);
     // return the called vars
     return $called_vars;
 }
 public function setUp()
 {
     $this->target = \Phake::partialMock('Mahotora\\DatabaseSessionImpl', array());
     $this->connection = \Phake::mock('\\mysqli');
     $this->statement = \Phake::mock('\\mysqli_stmt');
     $this->resultSet = \Phake::mock('\\mysqli_result');
     $this->target->setConnection($this->connection);
 }
 /**
  * @return EngineBlock_Corto_ProxyServer
  */
 private function mockProxyServer()
 {
     // Mock proxy server
     $_SERVER['HTTP_HOST'] = 'test-host';
     /** @var EngineBlock_Corto_ProxyServer $proxyServerMock */
     $proxyServerMock = Phake::partialMock('EngineBlock_Corto_ProxyServer');
     $proxyServerMock->setRepository(new InMemoryMetadataRepository(array(), array(new ServiceProvider('https://sp.example.edu'))))->setBindingsModule($this->mockBindingsModule());
     return $proxyServerMock;
 }
Exemple #7
0
 public function setUP()
 {
     $this->app = \Phake::partialMock('Dbup\\Application');
     $this->pdo = \Phake::mock('Dbup\\Database\\PdoDatabase');
     $this->dbh = \Phake::mock('\\Pdo');
     \Phake::when($this->pdo)->connection(\Phake::anyParameters())->thenReturn($this->dbh);
     $this->stmt = \Phake::mock('\\PDOStatement');
     \Phake::when($this->dbh)->prepare(\Phake::anyParameters())->thenReturn($this->stmt);
 }
Exemple #8
0
 public function setUp()
 {
     $this->next = \Phake::mock('\\Moshas\\Pipe');
     $this->entity = new Entity();
     $this->entity2 = new Entity();
     $this->entity3 = new Entity();
     $this->target = \Phake::partialMock('\\Moshas\\Pipe', $this->next);
     $this->lastTarget = \Phake::partialMock('\\Moshas\\Pipe');
 }
Exemple #9
0
 public function setUp()
 {
     $this->client = \Phake::mock('\\Moshas\\Twitter\\TwitterClient');
     $this->target = \Phake::partialMock('\\Moshas\\Twitter\\StatusPager', $this->client);
     \Phake::when($this->target)->buildUrl()->thenReturn('/url');
     \Phake::when($this->target)->buildQuery(null)->thenReturn(array('a' => 'b'));
     \Phake::when($this->target)->buildQuery(1233)->thenReturn(array('c' => 'd'));
     \Phake::when($this->client)->get('/url', array('a' => 'b'))->thenReturn((object) array('statuses' => array((object) array('id' => 1234, 'text' => 'hoge', 'created_at' => '2015-01-01 12:34', 'id_str' => '1234', 'user' => (object) array('screen_name' => 't_ishida', 'profile_image_url_https' => 'https://url/path/img.jpg')))));
     \Phake::when($this->client)->get('/url', array('c' => 'd'))->thenReturn((object) array('statuses' => array()));
 }
Exemple #10
0
 /**
  * @expectedException        Tokenly\APIClient\Exception\APIException
  * @expectedExceptionMessage Sample error
  */
 public function testErrorAPICall()
 {
     $api = Phake::partialMock('Tokenly\\APIClient\\TokenlyAPI', 'https://127.0.0.1/api/v1');
     Phake::when($api)->callRequest(Phake::anyParameters())->thenReturnCallback(function ($url, $headers, $body, $method, $options) {
         $response = new Requests_Response();
         $response->body = json_encode(['error' => 'Sample error']);
         return $response;
     });
     $api->call('POST', 'method/witherror', ['foo' => 'bar']);
 }
 protected function setUp()
 {
     parent::setUp();
     $this->tmpDirectory = __DIR__;
     $this->junitXMLFile = $this->tmpDirectory . '/' . $this->getName(false) . '.xml';
     $legacyProxy = \Phake::partialMock('Stagehand\\TestRunner\\Util\\LegacyProxy');
     \Phake::when($legacyProxy)->ob_get_level()->thenReturn(0);
     \Phake::when($legacyProxy)->system($this->anything(), $this->anything())->thenReturn(null);
     $this->setComponent('legacy_proxy', $legacyProxy);
     $this->configure();
 }
Exemple #12
0
 public function testSpecificSqlFile()
 {
     $application = \Phake::partialMock('Dbup\\Application');
     /** want not to run, so change up method to mock */
     \Phake::when($application)->up(\Phake::anyParameters())->thenReturn(null);
     $application->add(new UpCommand());
     $command = $application->find('up');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), '--ini' => __DIR__ . '/../.dbup/properties.ini.test', 'file' => 'V12__sample12_select.sql']);
     \Phake::verify($application, \Phake::times(1))->up(\Phake::anyParameters());
 }
 /** @test */
 public function should_load_proper_segment_config()
 {
     $mappingDir = realpath(__DIR__ . '/../../src/EDI/Mapping');
     /** @var MappingLoader $loader */
     $loader = \Phake::partialMock(MappingLoader::class, $mappingDir);
     $segmentPopulator = $this->givenSegmentPopulator();
     $populator = $this->givenPopulator($segmentPopulator, $loader);
     $fixtureDir = realpath(__DIR__ . '/../fixtures');
     $parser = new Parser();
     $data = $parser->parse($fixtureDir . '/invoic_message_standalone.edi');
     $populator->populate($data);
     \Phake::verify($loader)->loadMessage('D', '96A', 'INVOIC');
 }
 /**
  * @return EngineBlock_Corto_ProxyServer
  */
 private function mockProxyServer()
 {
     // Mock proxy server
     /** @var EngineBlock_Corto_ProxyServer $proxyServerMock */
     $proxyServerMock = Phake::partialMock('EngineBlock_Corto_ProxyServer');
     $proxyServerMock->setHostname('test-host');
     $proxyServerMock->setRepository(new InMemoryMetadataRepository(array(new IdentityProvider('testIdP')), array(new ServiceProvider('testSp'))));
     $bindingsModuleMock = $this->mockBindingsModule();
     $proxyServerMock->setBindingsModule($bindingsModuleMock);
     Phake::when($proxyServerMock)->renderTemplate(Phake::anyParameters())->thenReturn(null);
     Phake::when($proxyServerMock)->sendOutput(Phake::anyParameters())->thenReturn(null);
     return $proxyServerMock;
 }
Exemple #15
0
 public function testCreate()
 {
     $application = \Phake::partialMock('Dbup\\Application');
     $application->add(new CreateCommand());
     $command = $application->find('create');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'name' => 'foo', '--ini' => __DIR__ . '/../.dbup/properties.ini.test']);
     $display = $commandTester->getDisplay();
     assertThat($display, is(containsString('created')));
     preg_match('/\'(.+)\'/', $display, $matches);
     assertThat(1, count($matches));
     $migration = str_replace("'", "", $matches[0]);
     unlink(__DIR__ . '/../../../' . $migration);
 }
 public function testPublicAPICall()
 {
     $generator = new Generator();
     $api = Phake::partialMock('Tokenly\\APIClient\\TokenlyAPI', 'https://127.0.0.1/api/v1', $generator, 'MY_CLIENT_ID', 'MY_CLIENT_SECRET');
     $headers_generated = [];
     Phake::when($api)->callRequest(Phake::anyParameters())->thenReturnCallback(function ($url, $headers, $body, $method, $options) use(&$headers_generated) {
         $response = new Requests_Response();
         $response->body = json_encode(['sample' => 'output']);
         $headers_generated = $headers;
         return $response;
     });
     $result = $api->getPublic('method/one', ['foo' => 'bar']);
     PHPUnit::assertEquals(['sample' => 'output'], $result);
     // check headers
     PHPUnit::assertEmpty($headers_generated);
 }
Exemple #17
0
 public function testPoll()
 {
     $receiver = \Phake::mock('ZMQSocket');
     $sender = \Phake::mock('ZMQSocket');
     $controller = \Phake::mock('ZMQSocket');
     $poller = \Phake::mock('ZMQPoll');
     $worker = \Phake::partialMock('\\Brook\\Worker');
     $readable = array($receiver);
     $writeable = array();
     \Phake::when($poller)->poll(\Phake::setReference($readable), \Phake::setReference($writeable), \Brook\Worker::POLL_TIMEOUT)->thenReturn(1);
     $worker->setReceiver($receiver);
     $worker->setController($controller);
     $worker->setSender($sender);
     $worker->setPoller($poller);
     $readable = array($receiver);
     $writeable = array();
     \Phake::when($poller)->poll(\Phake::setReference($readable), \Phake::setReference($writeable), \Brook\Worker::POLL_TIMEOUT)->thenReturn(1);
     $this->assertEquals(\Brook\Worker::READ_READY, $worker->poll());
     $readable = array($controller);
     $writeable = array();
     \Phake::when($poller)->poll(\Phake::setReference($readable), \Phake::setReference($writeable), \Brook\Worker::POLL_TIMEOUT)->thenReturn(1);
     $this->assertEquals(\Brook\Worker::SHUTDOWN, $worker->poll());
 }
Exemple #18
0
 public function testSendOffWorker()
 {
     // make sure we exit the child
     $worker = \Phake::partialMock('\\Brook\\Worker');
     $fanOut = \Phake::partialMock('\\Brook\\FanOut');
     $task = \Phake::mock('\\Brook\\TaskInterface');
     $server = \Phake::mock('ZMQSocket');
     $controller = \Phake::mock('ZMQSocket');
     $sink = \Phake::mock('ZMQSocket');
     $fanOut->setServer($server);
     $fanOut->setController($controller);
     $fanOut->setSink($sink);
     \Phake::when($worker)->run($task)->thenReturn(true);
     \Phake::when($worker)->getPid()->thenReturn(0);
     \Phake::when($fanOut)->createWorker(7778, 7779, 7780)->thenReturn($worker);
     \Phake::when($fanOut)->exitChild()->thenReturn(true);
     \Phake::when($fanOut)->initialize()->thenReturn(true);
     $this->assertEquals($worker, $fanOut->sendOffWorker($task));
     \Phake::verify($fanOut)->createWorker(7778, 7779, 7780);
     \Phake::verify($worker)->run();
     \Phake::verify($worker)->getPid();
     \Phake::verify($fanOut)->exitChild();
 }
Exemple #19
0
    public function setUp()
    {
        $this->pdo = Phake::partialMock('PDO', $_ENV['SQLite_Store_DSN']);
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $this->pdo->exec('DROP TABLE IF EXISTS `stuff`;');
        $this->pdo->exec('create table `stuff` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` varchar(100) );');
        $this->pdo->exec('DROP TABLE IF EXISTS `some_stuff`;');
        $this->pdo->exec('CREATE TABLE `some_stuff` (
  			`some_id` int(10)  NOT NULL,
  			`stuff_id` int(10)  NOT NULL,
  			`name` VARCHAR(100),
			PRIMARY KEY (`some_id`,`stuff_id`));');
        $this->pdo->exec('DROP TABLE IF EXISTS `some_other_stuff`;');
        $this->pdo->exec('CREATE TABLE `some_other_stuff` (
  			`some_id` int(10)  NOT NULL,
  			`stuff_id` int(10)  NOT NULL,
  			`name` VARCHAR(100),
			PRIMARY KEY( "some_id" , "stuff_id" ));');
        $this->pdo->exec('DROP TABLE IF EXISTS `group`;');
        $this->pdo->exec('create table `group` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255));');
        $this->pdo->exec('DROP TABLE IF EXISTS `no_pk`;');
        $this->pdo->exec('create table `no_pk` ( `id` INTEGER, `name` VARCHAR(255));');
        $this->driver = SqlStore::fromPdo($this->pdo);
    }
 public function setUp()
 {
     $this->target = \Phake::partialMock('\\Moshas\\Twitter\\ApplicationClient', 'hoge', 'fuga');
     $this->target2 = new \Moshas\Twitter\ApplicationClient('hoge', 'fuga', 'piyo');
 }
 public function setUp()
 {
     Phake::initAnnotations($this);
     $this->matcher = Phake::partialMock('Phake_Matchers_AbstractChainableArgumentMatcher');
 }
 /**
  * @test
  */
 public function testGetBundleForClass()
 {
     $listener = \Phake::partialMock('Xnni\\Bundle\\MobileViewBundle\\View\\UserAgentSpecificViewListener', static::$kernel->getContainer());
     $bundle1 = \Phake::mock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');
     \Phake::when($bundle1)->getNamespace()->thenReturn('namespace1');
     $bundle2 = \Phake::mock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');
     \Phake::when($bundle2)->getNamespace()->thenReturn('Vendor\\Bundle\\TestBundle');
     $kernelMock = \Phake::mock('Symfony\\Component\\HttpKernel\\KernelInterface');
     \Phake::when($kernelMock)->getBundles()->thenReturn(array($bundle1, $bundle2));
     static::$kernel->getContainer()->set('kernel', $kernelMock);
     // test target (protected)
     $class = new \ReflectionClass('Xnni\\Bundle\\MobileViewBundle\\View\\UserAgentSpecificViewListener');
     $method = $class->getMethod('getBundleForClass');
     $method->setAccessible(true);
     $retBundle = $method->invokeArgs($listener, array('Vendor\\Bundle\\TestBundle\\Controller\\TestController'));
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface', $retBundle);
     $this->assertEquals($bundle2, $retBundle);
 }
 protected function setUp()
 {
     $this->event = \Phake::partialMock('\\LaunchKey\\SDK\\Event\\AbstractEvent');
 }
Exemple #24
0
 /**
  * @expectedException \Piece\Flow\PageFlow\PageFlowNotActivatedException
  * @since Method available since Release 2.0.0
  *
  * @test
  */
 public function raisesAnExceptionWhenAnEventIsTriggeredIfThePageFlowIsNotActive()
 {
     $pageFlow = \Phake::partialMock('Piece\\Flow\\PageFlow\\PageFlow', 'foo');
     $pageFlow->triggerEvent('bar');
 }
 /**
  * @param string $type
  * @return Renderer\AbstractRenderer
  */
 private function getRendererMock($type)
 {
     $renderer = Phake::partialMock('\\Arjf\\DesignPatterns\\Behavioural\\TemplateMethod\\Renderer\\' . $type);
     return $renderer;
 }
 public function testReferencesPassedThrough()
 {
     $this->matcher = Phake::partialMock('Phake_Matchers_SingleArgumentMatcher');
     $args = array('test arg1');
     Phake::when($this->matcher)->matches(Phake::setReference('new value'))->thenReturn(true);
     $this->matcher->doArgumentsMatch($args);
     $this->assertEquals('new value', $args[0]);
 }
 public function setUp()
 {
     CorrelationDataHolder::clear();
     $this->sagaRepository = \Phake::partialMock(InMemorySagaRepository::class);
     $this->manager = new AnnotatedSagaManager($this->sagaRepository, new GenericSagaFactory(), array(MyTestSaga::class));
 }
Exemple #28
0
 public function testMockingAbstractClass()
 {
     $mock = Phake::partialMock('PhakeTest_AbstractClass');
     $this->assertNull($mock->referenceDefault());
 }
 /**
  * @test
  * @dataProvider options
  */
 public function transformsOptionsToConfiguration(array $options, \Closure $preparer, \Closure $verifier)
 {
     $transformation = \Phake::partialMock('Stagehand\\TestRunner\\DependencyInjection\\Transformation\\Transformation', $this->applicationContext->getComponentFactory()->getContainer(), $this->getPlugin());
     $command = \Phake::partialMock('Stagehand\\TestRunner\\CLI\\TestRunnerApplication\\Command\\' . $this->getPluginID() . 'Command');
     \Phake::when($command)->createContainer($this->anything())->thenReturn($this->applicationContext->getComponentFactory()->getContainer());
     \Phake::when($command)->createTransformation($this->anything())->thenReturn($transformation);
     $testRunner = \Phake::mock('Stagehand\\TestRunner\\Process\\TestRunner');
     \Phake::when($testRunner)->run()->thenReturn(null);
     $this->applicationContext->setComponent('test_runner', $testRunner);
     $preparer($this, $this->applicationContext, $transformation);
     $command->run(new ArgvInput(array_merge(array('testrunner', strtolower($this->getPluginID())), $options)), new ConsoleOutput());
     $verifier($this, $this->applicationContext, $transformation);
 }
Exemple #30
0
 protected function setUp()
 {
     $this->target = \Phake::partialMock('\\Moshas\\Text\\Parse\\Yahoo', 'hoge', 'fuga');
 }