public function testConfigureCustomAggregateFactory() { $this->fixture->registerAggregateFactory($this->mockAggregateFactory); $this->fixture->registerAnnotatedCommandHandler(new MyCommandHandler($this->fixture->getRepository(), $this->fixture->getEventBus())); $this->fixture->given([new MyEvent("id1", 1)])->when(new TestCommand("id1")); \Phake::verify($this->mockAggregateFactory, \Phake::atLeast(1))->createAggregate(\Phake::equalTo("id1"), \Phake::anyParameters()); }
/** * Tests using an equalTo argument matcher with a method stub */ public function testStubWithEqualsMatcher() { $mock = Phake::mock('PhakeTest_MockedClass'); Phake::when($mock)->fooWithArgument(Phake::equalTo('bar'))->thenReturn(42); $this->assertEquals(42, $mock->fooWithArgument('bar')); $this->assertNull($mock->fooWithArgument('test')); }
public function testFindsByCompoundPrimaryKeyAndSequence() { $bp = new Blueprint($this->machinist, 'test_table', array('column1' => "hello", 'column2' => "dumb")); $expected = array('key1' => 8, 'key2' => 12, 'column1' => "hello", 'column2' => "dumb"); Phake::when($this->store)->insert(Phake::equalTo("test_table"), Phake::equalTo(array('column1' => "hello", 'column2' => "dumb", "key1" => 8)))->thenReturn(12); Phake::when($this->store)->primaryKey("test_table")->thenReturn(array('key1', 'key2')); Phake::when($this->store)->find(Phake::equalTo("test_table"), Phake::equalTo(array('key1' => 8, 'key2' => 12)))->thenReturn(array($expected)); $actual = $bp->make(array('key1' => 8, 'key2' => 12)); $this->assertEquals($actual->toArray(), $expected); }
public function testMatcherSetsNextMatcherInChain() { $matcher1 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher'); $matcher2 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher'); /* @var $newMatcher Phake_Matchers_IChainableArgumentMatcher */ $this->factory->createMatcher($matcher2); $this->factory->createMatcher($matcher1, $matcher2); $this->assertNull($matcher2->getNextMatcher()); Phake::verify($matcher1)->setNextMatcher(Phake::equalTo($matcher2)); }
public function testTransactionBoundUnitOfWorkLifecycle_Rollback() { $mockListener = \Phake::mock(UnitOfWorkListenerInterface::class); $mockTransactionManager = \Phake::mock(TransactionManagerInterface::class); \Phake::when($mockTransactionManager)->startTransaction()->thenReturn(new \stdClass()); $uow = DefaultUnitOfWork::startAndGet($mockTransactionManager); $uow->registerListener($mockListener); \Phake::verify($mockTransactionManager)->startTransaction(); \Phake::verifyNoInteraction($mockListener); $uow->rollback(); \Phake::inOrder(\Phake::verify($mockTransactionManager)->rollbackTransaction(\Phake::anyParameters()), \Phake::verify($mockListener)->onRollback(\Phake::anyParameters()), \Phake::verify($mockListener)->onCleanup(\Phake::equalTo($uow))); }
public function test_register_session_index_writes_data_to_the_table() { $start = time(); $this->service->register_session_index(); $end = time(); $expected = "INSERT INTO prefix_launchkey_sso_sessions VALUES (%s, %s) ON DUPLICATE KEY UPDATE seen = %s"; Phake::inOrder(Phake::verify($this->wpdb)->prepare($expected, Phake::equalTo("id-b4373c87a6f18f97862c931744fd799f"), Phake::capture($insert_date_string), Phake::capture($update_date_string)), Phake::verify($this->wpdb)->query(static::PREPARED_STARTEMENT)); $this->assertEquals($insert_date_string, $update_date_string, "Insert and update date strings were expected to be the same but were not"); $this->assertRegExp('/[12][0-9]{3}-[0-9]{2}-[0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/', $insert_date_string, "Date strings are not in MYSQL date format"); $sql_time = strtotime($insert_date_string); $this->assertGreaterThanOrEqual($start, $sql_time, sprintf("Date string of %s is not on or after recorded start time of %s", $insert_date_string, date('Y-m-d H:i:s', $start))); $this->assertLessThanOrEqual($end, $sql_time, sprintf("Date string of %s is not on or after recorded start time of %s", $insert_date_string, date('Y-m-d H:i:s', $end))); }
public function testSendMessageWithPublisherAck_NoActiveUnitOfWork() { $this->testSubject->setTransactional(false); $this->testSubject->setWaitForPublisherAck(true); $channel = \Phake::mock(AMQPChannel::class); \Phake::when($channel)->wait_for_pending_acks()->thenReturn(null); \Phake::when($this->connection)->channel()->thenReturn($channel); $message = new GenericEventMessage(new Payload("Message")); \Phake::when($this->serializer)->serialize(\Phake::equalTo($message->getPayload()))->thenReturn(new SimpleSerializedObject(json_encode($message->getPayload()), new SimpleSerializedType(Payload::class))); \Phake::when($this->serializer)->serialize(\Phake::equalTo($message->getMetaData()))->thenReturn(new SimpleSerializedObject(json_encode(array('metadata' => array())), new SimpleSerializedType(MetaData::class))); $this->testSubject->publish(array($message)); \Phake::verify($channel)->confirm_select(); \Phake::verify($channel)->basic_publish(\Phake::anyParameters()); \Phake::verify($channel)->wait_for_pending_acks(\Phake::anyParameters()); }