/** * @param string $method * @param array $params * @param array $expectedParams * @param mixed $expectedResult * @dataProvider proxyMethodDataProvider */ public function testProxyMethod($method, $params, $expectedParams, $expectedResult) { $frontendMock = $this->getMock('Zend_Cache_Core'); $object = new \Magento\Framework\Cache\Frontend\Adapter\Zend($frontendMock); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $expectedResult, $method, $expectedParams); $this->assertSame($expectedResult, $result); }
/** * @param string $method * @param array $params * @param mixed $expectedResult * @dataProvider proxyMethodDataProvider */ public function testProxyMethod($method, $params, $expectedResult) { $frontendMock = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $object = new \Magento\Framework\Cache\Frontend\Decorator\Bare($frontendMock); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $expectedResult); $this->assertSame($expectedResult, $result); }
/** * @param string $method * @param array $params * @param bool $disabledResult * @param mixed $enabledResult * @dataProvider proxyMethodDataProvider */ public function testProxyMethod($method, $params, $disabledResult, $enabledResult) { $identifier = 'cache_type_identifier'; $frontendMock = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $cacheEnabler = $this->getMock('Magento\\Framework\\App\\Cache\\StateInterface'); $cacheEnabler->expects($this->at(0))->method('isEnabled')->with($identifier)->will($this->returnValue(false)); $cacheEnabler->expects($this->at(1))->method('isEnabled')->with($identifier)->will($this->returnValue(true)); $object = new \Magento\Framework\App\Cache\Type\AccessProxy($frontendMock, $cacheEnabler, $identifier); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); // For the first call the cache is disabled - so fake default result is returned $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $enabledResult); $this->assertSame($disabledResult, $result); // For the second call the cache is enabled - so real cache result is returned $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $enabledResult); $this->assertSame($enabledResult, $result); }
/** * @param string $method * @param array $params * @param mixed $proxiedResult * @param string|null $proxiedMethod * @param string|null $proxiedParams * @param string $callProxiedMethod * @param array $passProxiedParams * @param mixed $expectedResult * * @dataProvider invokeWithExpectationsDataProvider */ public function testInvokeWithExpectations($method, $params, $proxiedResult, $proxiedMethod, $proxiedParams, $callProxiedMethod, $passProxiedParams, $expectedResult) { // Create proxied object with $callProxiedMethod $proxiedObject = $this->getMock('stdClass', [$callProxiedMethod]); // Create object, which reacts on called $method by calling $callProxiedMethod from proxied object $callProxy = function () use($proxiedObject, $callProxiedMethod, $passProxiedParams) { return call_user_func_array([$proxiedObject, $callProxiedMethod], $passProxiedParams); }; $object = $this->getMock('stdClass', [$method]); $builder = $object->expects($this->once())->method($method); call_user_func_array([$builder, 'with'], $params); $builder->will($this->returnCallback($callProxy)); // Test it $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); $result = $helper->invokeWithExpectations($object, $proxiedObject, $method, $params, $proxiedResult, $proxiedMethod, $proxiedParams); $this->assertSame($expectedResult, $result); }
/** * @param string $method * @param array $params * @param \Zend_Cache_Backend $cacheBackend * @param \Zend_Cache_Core $cacheFrontend * @param string $expectedProfileId * @param array $expectedProfilerTags * @param mixed $expectedResult * @dataProvider proxyMethodDataProvider */ public function testProxyMethod($method, $params, $cacheBackend, $cacheFrontend, $expectedProfileId, $expectedProfilerTags, $expectedResult) { // Cache frontend setup $frontendMock = $this->getMock('Magento\\Framework\\Cache\\FrontendInterface'); $frontendMock->expects($this->any())->method('getBackend')->will($this->returnValue($cacheBackend)); $frontendMock->expects($this->any())->method('getLowLevelFrontend')->will($this->returnValue($cacheFrontend)); // Profiler setup $driver = $this->getMock('Magento\\Framework\\Profiler\\DriverInterface'); $driver->expects($this->once())->method('start')->with($expectedProfileId, $expectedProfilerTags); $driver->expects($this->once())->method('stop')->with($expectedProfileId); \Magento\Framework\Profiler::add($driver); // Test $object = new \Magento\Framework\Cache\Frontend\Decorator\Profiler($frontendMock, ['Zend_Cache_Backend_']); $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $expectedResult); $this->assertSame($expectedResult, $result); }
/** * @param string $method * @param array $params * @param mixed $expectedResult * @dataProvider proxyMethodDataProvider */ public function testProxyMethod($method, $params, $expectedResult) { $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting(); $result = $helper->invokeWithExpectations($this->model, $this->frontendMock, $method, $params, $expectedResult); $this->assertSame($expectedResult, $result); }