protected function setUp()
 {
     $options = array();
     $options['area'] = current(TestUtil::getAnnotationByNameFromClass(__CLASS__, 'area', 'method', $this->getName(false)));
     $options['package'] = current(TestUtil::getAnnotationByNameFromClass(__CLASS__, 'package', 'method', $this->getName(false)));
     $options['theme'] = current(TestUtil::getAnnotationByNameFromClass(__CLASS__, 'theme', 'method', $this->getName(false)));
     $options['store_id'] = current(TestUtil::getAnnotationByNameFromClass(__CLASS__, 'storeId', 'method', $this->getName(false)));
     $this->source = new EcomDev_LayoutCompiler_Model_Layout_Source_Database($options);
 }
 /**
  * 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;
 }
 /**
  * Creates a mockery for session
  *
  * @param string $classAlias
  * @param array  $methods
  *
  * @return EcomDev_PHPUnit_Mock_Proxy
  */
 public function helperMockSession($classAlias, array $methods = array())
 {
     if (!empty($methods) && !in_array('start', $methods, true)) {
         $methods[] = 'start';
     }
     $sessionMock = EcomDev_PHPUnit_Helper::invoke('mockModel', $classAlias, $methods)->disableOriginalConstructor();
     TestUtil::replaceByMock('singleton', $classAlias, $sessionMock);
     $sessionMock->expects($this->testCase->any())->method('start')->willReturnSelf();
     return $sessionMock;
 }
Beispiel #4
0
 /**
  * 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;
 }
 /**
  * Returns processed file path based on module test directory
  *
  * @param string $fileName
  * @param string $relatedClassName
  * @param string $type
  * @return string|bool
  */
 protected function _getFilePath($fileName, $relatedClassName, $type)
 {
     $moduleName = false;
     if (preg_match('#^~(?<module>[^/]*)/(?<fileName>.*)$#', $fileName, $matches)) {
         $fileName = $matches['fileName'];
         if (!empty($matches['module'])) {
             $moduleName = $matches['module'];
         }
     }
     if (!$moduleName) {
         try {
             $moduleName = EcomDev_PHPUnit_Test_Case_Util::getModuleNameByClassName($relatedClassName);
         } catch (RuntimeException $e) {
             return false;
         }
     }
     $basePath = array();
     if ($prefixPosition = strpos($relatedClassName, $moduleName . '_Test_')) {
         $testType = substr($relatedClassName, $prefixPosition, strpos($relatedClassName, '_', $prefixPosition));
         $basePath[] = Mage::getModuleDir('', $moduleName) . DS . 'Test' . DS . $testType;
     }
     $basePath[] = Mage::getModuleDir('', $moduleName) . DS . 'Test';
     return $this->_checkFilePath($basePath, $fileName, $type);
 }
 /**
  * Sets back old singletons after tests
  *
  * @param array[]                                 $data
  * @param string                                  $key
  * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
  *
  * @return EcomDev_PHPUnit_Model_Fixture_ProcessorInterface
  */
 public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
 {
     if ($fixture->getStorageData(self::STORAGE_KEY) === null) {
         return $this;
     }
     $oldRegistry = $fixture->getStorageData(self::STORAGE_KEY);
     foreach ($oldRegistry as $key => $value) {
         // Set old value to registry
         EcomDev_PHPUnit_Test_Case_Util::app()->replaceRegistry($key, $value);
     }
     $fixture->setStorageData(self::STORAGE_KEY, null);
     return $this;
 }
Beispiel #7
0
 /**
  * Load YAML file
  *
  * @param string $filePath
  * @return EcomDev_PHPUnit_Model_Fixture
  * @throws InvalidArgumentException if file is not a valid YAML file
  */
 public function loadYaml($filePath)
 {
     $data = EcomDev_PHPUnit_Test_Case_Util::getYamlLoader()->load($filePath);
     if (empty($this->_fixture)) {
         $this->_fixture = $data;
     } else {
         $this->_fixture = array_merge_recursive($this->_fixture, $data);
     }
     return $this;
 }
 protected function setUp()
 {
     $className = current(EcomDev_PHPUnit_Test_Case_Util::getAnnotationByNameFromClass(__CLASS__, 'className', 'method', $this->getName(false)));
     $this->parser = new EcomDev_LayoutCompiler_Model_Compiler_Parser_Action($className);
 }
Beispiel #9
0
 /**
  * Invokes replaceByMock test util method with current mock object proxy instance
  * 
  * @param $type
  * @return $this
  */
 public function replaceByMock($type)
 {
     EcomDev_PHPUnit_Test_Case_Util::replaceByMock($type, $this->classAlias, $this);
     return $this;
 }
Beispiel #10
0
 /**
  * Creates a mockery for a class alias of particular type
  *
  * @param string $type
  * @param string $classAlias
  * @param array $methods
  * @param array $constructorArgs
  *
  * @return EcomDev_PHPUnit_Mock_Proxy
  */
 public function helperMockClassAlias($type, $classAlias, array $methods = array(), array $constructorArgs = array())
 {
     return TestUtil::getGroupedClassMockBuilder($this->testCase, $type, $classAlias)->setConstructorArgs($constructorArgs)->setMethods($methods);
 }
Beispiel #11
0
 /**
  * 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));
 }
 /**
  * performs the following cleanup tasks:
  * - discards fixtures
  * @return null
  */
 public function tearDown()
 {
     Mage::app()->setCurrentStore(Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID);
     EcomDev_PHPUnit_Test_Case_Util::tearDown();
 }
Beispiel #13
0
 /**
  * Discard applied cache options
  *
  * @param array[] $data
  * @param string $key
  * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
  *
  * @return EcomDev_PHPUnit_Model_Fixture_Processor_Cache
  */
 public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
 {
     EcomDev_PHPUnit_Test_Case_Util::app()->setCacheOptions($fixture->getStorageData(self::STORAGE_KEY));
     return $this;
 }
Beispiel #14
0
 /**
  * Set associated module name for a class name,
  * Usually used for making possible dependency injection in the test cases
  *
  *
  * @param string $className
  * @param string $moduleName
  * @return EcomDev_PHPUnit_Model_App
  * @deprecated since 0.3.0
  */
 public function setModuleNameForClassName($className, $moduleName)
 {
     EcomDev_PHPUnit_Test_Case_Util::setModuleNameForClassName($className, $moduleName);
     return $this;
 }
 /**
  * Discard applied attribute records
  *
  * @param array[] $data
  * @param string $key
  * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
  *
  * @return EcomDev_PHPUnit_Model_Fixture_Processor_Attributes
  */
 public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
 {
     $ignoreCleanUp = array();
     // Ignore cleaning of entities if shared fixture loaded something for them
     if ($fixture->isScopeLocal() && $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)) {
         $ignoreCleanUp = $fixture->getStorageData(self::STORAGE_KEY, EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED);
     }
     $this->getResource()->beginTransaction();
     foreach (array_keys($data) as $entityType) {
         if (in_array($entityType, $ignoreCleanUp)) {
             continue;
         }
         $this->_getAttributeLoader($entityType)->cleanAttributes($entityType, $data);
     }
     $this->getResource()->commit();
     EcomDev_PHPUnit_Test_Case_Util::replaceRegistry('_singleton/eav/config', null);
     //clean out the EAV cache
     return $this;
 }
Beispiel #16
0
 /**
  * Calling of the helper method
  *
  * @param string $method
  * @param array $args
  * @return mixed
  */
 public function __call($method, array $args)
 {
     return TestUtil::call($method, $args);
 }
Beispiel #17
0
 /**
  * Discard applied scope models
  *
  * @param array[] $data
  * @param string $key
  * @param EcomDev_PHPUnit_Model_FixtureInterface $fixture
  *
  * @return EcomDev_PHPUnit_Model_Fixture_Processor_Scope
  */
 public function discard(array $data, $key, EcomDev_PHPUnit_Model_FixtureInterface $fixture)
 {
     if ($fixture->getStorageData(self::STORAGE_KEY) === null) {
         return $this;
     }
     EcomDev_PHPUnit_Test_Case_Util::app()->disableEvents();
     $scope = array_reverse($fixture->getStorageData(self::STORAGE_KEY));
     foreach ($scope as $models) {
         foreach ($models as $model) {
             $model->delete();
         }
     }
     $fixture->setStorageData(self::STORAGE_KEY, null);
     EcomDev_PHPUnit_Test_Case_Util::app()->getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array(Mage_Core_Model_Store::CACHE_TAG, Mage_Core_Model_Store_Group::CACHE_TAG, Mage_Core_Model_Website::CACHE_TAG));
     EcomDev_PHPUnit_Test_Case_Util::app()->enableEvents();
     EcomDev_PHPUnit_Test_Case_Util::app()->reinitStores();
     return $this;
 }
Beispiel #18
0
 /**
  * Called for each test case
  *
  */
 public static function tearDown()
 {
     if (self::$originalStore) {
         self::app()->setCurrentStore(self::$originalStore);
         self::$originalStore = null;
     }
     self::app()->getConfig()->flushReplaceInstanceCreation();
     self::app()->getLayout()->flushReplaceBlockCreation();
     foreach (self::$replacedRegistry as $registryPath => $originalValue) {
         self::app()->replaceRegistry($registryPath, $originalValue);
     }
 }
 /**
  * Loads expected data from test case annotations
  *
  * @see EcomDev_PHPUnit_Model_Test_LoadableInterface::loadByTestCase()
  */
 public function loadByTestCase(PHPUnit_Framework_TestCase $testCase)
 {
     $expectations = EcomDev_PHPUnit_Test_Case_Util::getAnnotationByNameFromClass(get_class($testCase), 'loadExpectation', array('class', 'method'), $testCase->getName(false));
     if (!$expectations) {
         $expectations[] = $testCase->getName(false);
     }
     $expectationData = array();
     foreach ($expectations as $expectation) {
         if (empty($expectation)) {
             $expectation = $testCase->getName(false);
         }
         $expectationFile = EcomDev_PHPUnit_Test_Case_Util::getYamlLoader(get_class($testCase))->resolveFilePath(get_class($testCase), EcomDev_PHPUnit_Model_Yaml_Loader::TYPE_EXPECTATION, $expectation);
         if (!$expectationFile) {
             $text = 'There was no expectation defined for current test case';
             if ($expectation) {
                 $text = sprintf('Cannot load expectation %s', $expectation);
             }
             throw new RuntimeException($text);
         }
         $expectationData = array_merge_recursive($expectationData, EcomDev_PHPUnit_Test_Case_Util::getYamlLoader()->load($expectationFile));
     }
     $this->_loadedData = new Varien_Object($expectationData);
     return $this;
 }
Beispiel #20
0
 /**
  * Creates a mockery for session
  *
  * @param string $classAlias
  * @param array  $methods
  *
  * @return EcomDev_PHPUnit_Mock_Proxy
  */
 public function helperMockSession($classAlias, array $methods = array())
 {
     $sessionMock = EcomDev_PHPUnit_Helper::invoke('mockModel', $classAlias, $methods)->disableOriginalConstructor();
     TestUtil::replaceByMock('singleton', $classAlias, $sessionMock);
     return $sessionMock;
 }