/** * Logs in as a customer by customer id and store id * * @param int $customerId * @param string|int|null $storeId * * @return EcomDev_PHPUnit_Mock_Proxy */ public function helperCustomerSession($customerId, $storeId = null) { $customerSessionMock = TestHelper::invoke('mockSession', 'customer/session', array('renewSession')); if ($storeId === null) { $storeId = TestUtil::app()->getAnyStoreView()->getCode(); } TestUtil::setCurrentStore($storeId); $customerSessionMock->loginById($customerId); return $customerSessionMock; }
/** * Registers default test helpers * */ public function registerDefaultTestHelpers() { foreach (Mage::getConfig()->getNode(self::XML_PATH_TEST_HELPERS)->children() as $helperNode) { $helperClass = (string) $helperNode; if ($helperClass && class_exists($helperClass)) { $helper = new $helperClass(); if (!$helper instanceof EcomDev_PHPUnit_HelperInterface) { throw new RuntimeException(sprintf('Test helpers should implement %s, but %s is not implementing it.', 'EcomDev_PHPUnit_HelperInterface', $helperClass)); } EcomDev_PHPUnit_Helper::add($helper); } } }
/** * Start session as guest. * * @param string|int|null $storeId * * @return EcomDev_PHPUnit_Mock_Proxy */ public function helperGuestSession($storeId = null) { $guestSessionMock = TestHelper::invoke('mockSession', 'core/session', array('renewSession')); /** @var Mage_Core_Model_Session $session */ $session = $guestSessionMock->getMock(); $_GET[$session->getSessionIdQueryParam()] = $session->getSessionId(); // some action need that (loginPost, ...) if ($storeId === null) { $storeId = TestUtil::app()->getAnyStoreView()->getCode(); } TestUtil::setCurrentStore($storeId); return $guestSessionMock; }
/** * A test ended. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(PHPUnit_Framework_Test $test, $time) { Mage::dispatchEvent('phpunit_test_end_before', array('test' => $test, 'listener' => $this)); if ($test instanceof PHPUnit_Framework_TestCase) { EcomDev_PHPUnit_Test_Case_Util::getFixture(get_class($test))->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_LOCAL)->discard(); // Clear applied fixture if (EcomDev_PHPUnit_Test_Case_Util::getExpectation(get_class($test))->isLoaded()) { EcomDev_PHPUnit_Test_Case_Util::getExpectation(get_class($test))->discard(); } EcomDev_PHPUnit_Test_Case_Util::tearDown(); EcomDev_PHPUnit_Helper::tearDown(); } Mage::dispatchEvent('phpunit_test_end_after', array('test' => $test, 'listener' => $this)); }
/** * Implementation of __call method functionality that can be used from a test case * * @param string $method * @param array $args * * @throws ErrorException * @return bool */ public static function call($method, $args) { if (TestHelper::has($method)) { return TestHelper::invokeArgs($method, $args); } if (version_compare(PHP_VERSION, '5.4', '>=')) { $backTraceCalls = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3); } else { // We cannot limit number of arguments on php before 5.4, php rises an exception :( $backTraceCalls = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT); } $previousCall = $backTraceCalls[2]; throw new ErrorException(sprintf('Call to undefined function %s%s%s()', $previousCall['class'], $previousCall['type'], $previousCall['function']), 0, E_USER_ERROR, $previousCall['file'], $previousCall['line']); }
/** * Creates a new instance of user with unique id * * Used for stubbing admin user roles * * @param int $entropy * @return Mage_Admin_Model_User */ public function createUser($entropy = 3) { $userId = floor(microtime(true) * pow(10, $entropy) - floor(time() / 100) * 100 * pow(10, $entropy)); // Fix for EE gws functionality $userRole = Mage::getModel('admin/roles'); $userRole->setGwsIsAll(1); $user = EcomDev_PHPUnit_Helper::invoke('mockModel', 'admin/user', array('reload'))->getMockInstance(); $user->setId($userId); EcomDev_Utils_Reflection::setRestrictedPropertyValue($user, '_role', $userRole); return $user; }
/** * Test that when set up is invoked, * test helpers that support setUp method invoked as well * */ public function testTearDown() { $helpers = $this->getHelpersForTest(4, true); $helpers[0]->expects($this->never())->method('tearDown'); $helpers[1]->expects($this->once())->method('tearDown'); $helpers[2]->expects($this->never())->method('tearDown'); $helpers[3]->expects($this->once())->method('tearDown'); EcomDev_PHPUnit_Helper::tearDown(); }
public function tearDown() { EcomDev_PHPUnit_Helper::remove($this->helper); }