public function testInitializer() { // Saving initializer job Mage::getModel('xcom_initializer/job')->setTopic('productTaxonomy/productType/get')->setStatus(Xcom_Initializer_Model_Job::STATUS_PENDING)->setMessageParams(json_encode(array('country' => 'US', 'language' => 'en')))->setIssuer($this->_issuer)->save(); $this->addRollbackQuery(sprintf('delete from xcom_initializer_job where issuer="%s"', $this->_issuer)); // Checking whether it was actually saved $select = $this->getConnection()->select()->from('xcom_initializer_job', array('*'))->where('issuer = ?', $this->_issuer); $result = $this->getConnection()->fetchOne($select); $this->assertNotEmpty($result); // Running method which sends data from saved job /* @var $observer Xcom_Initializer_Model_Observer */ $observer = Mage::getModel('xcom_initializer/observer'); // @todo remove and replace with checking testsubscriber for arrived message Mage::app()->getStore()->setConfig('xfabric/connection_settings/adapter', 'xcom_stub/transport_stub'); Mage::app()->getStore()->setConfig('xfabric/connection_settings/encoding', 'json'); $observer->runCollectProcess(new Varien_Event_Observer()); // Check whether saved job has been sent $select = $this->getConnection()->select()->from('xcom_initializer_job', array('status'))->where('issuer = ?', $this->_issuer); $result = $this->getConnection()->fetchOne($select); $constraint = new PHPUnit_Framework_Constraint_Or(); $constraint->setConstraints(array(Xcom_Initializer_Model_Job::STATUS_SENT, Xcom_Initializer_Model_Job::STATUS_RECEIVED)); $this->assertThat($result, $constraint); // Make sure stop actions work while not all messages has been processed $this->_ensureDenied($this->makeHttpRequest('/initializertest/index/some')); $this->_ensureAllowed($this->makeHttpRequest('/initializertest/index/index')); // Imitate that we've processed received results $this->getConnection()->update('xcom_initializer_job', array('status' => Xcom_Initializer_Model_Job::STATUS_SAVED), sprintf('issuer = "%s"', $this->_issuer)); // Make sure stop actions doesn't work anymore $this->_ensureAllowed($this->makeHttpRequest('/initializertest/index/some')); }
/** * @return \PHPUnit_Framework_MockObject_MockObject */ private function getEntityManagerMock() { $itemMock = $this->getMock(Item::class); $itemMock->expects($this->any())->method('getId')->will($this->returnValue(1)); $itemRepositoryMock = $this->getMockBuilder(ItemRepository::class)->disableOriginalConstructor()->getMock(); $constraint = new \PHPUnit_Framework_Constraint_Or(); $constraint->setConstraints(['update', 'add']); $itemRepositoryMock->expects($this->once())->method($constraint)->will($this->returnValue($itemMock)); $emMock = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); $emMock->expects($this->once())->method('getRepository')->with('RestApiBundle:Item')->will($this->returnValue($itemRepositoryMock)); return $emMock; }
public function testFormActionIsContentGenerated() { $this->dispatch('paypal/payflow/form'); $this->assertContains('<form id="token_form" method="GET" action="https://payflowlink.paypal.com">', $this->getResponse()->getBody()); // Check P3P header $headerConstraints = []; foreach ($this->getResponse()->getHeaders() as $header) { $headerConstraints[] = new \PHPUnit_Framework_Constraint_IsEqual($header->getFieldName()); } $constraint = new \PHPUnit_Framework_Constraint_Or(); $constraint->setConstraints($headerConstraints); $this->assertThat('P3P', $constraint); }
/** * @dataProvider functionsDataProvider * @param array $functions * @param string $dql * @param string $sql * @param string $expectedResult */ public function testDqlFunction(array $functions, $dql, $sql, $expectedResult) { $configuration = $this->entityManager->getConfiguration(); foreach ($functions as $function) { $this->registerDqlFunction($function['type'], $function['name'], $function['className'], $configuration); } $query = new Query($this->entityManager); $query->setDQL($dql); if (is_array($sql)) { $constraints = array(); foreach ($sql as $sqlVariant) { $constraints[] = $this->equalTo($sqlVariant); } $constraint = new \PHPUnit_Framework_Constraint_Or(); $constraint->setConstraints($constraints); $this->assertThat($query->getSQL(), $constraint); } else { $this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql)); } $result = $query->getArrayResult(); $this->assertNotEmpty($result); $this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql)); }
/** * Logical OR. * * @return PHPUnit_Framework_Constraint_Or * @access public * @since Method available since Release 3.0.0 * @static */ public static function logicalOr() { $constraints = func_get_args(); $constraint = new PHPUnit_Framework_Constraint_Or(); $constraint->setConstraints($constraints); return $constraint; }