To enable the autoloading of mocks you simply need to make a simple method call. {{{ use lithium\core\Environment; use lithium\test\Mocker; if (!Environment::is('production')) { Mocker::register(); } }}} You can also enable autoloading inside the setup of a unit test class. This method can be called redundantly. {{{ use lithium\test\Mocker; class MockerTest extends \lithium\test\Unit { public function setUp() { Mocker::register(); } } }}} Using Mocker is the fun magical part, it's autoloaded so simply call the class you want to mock with the '\Mock' at the end. The autoloader will detect you want to autoload it, and create it for you. Now you can filter any method. {{{ use lithium\console\dispatcher\Mock as DispatcherMock; $dispatcher = new DispatcherMock(); $dispatcher->applyFilter('config', function($self, $params, $chain) { return array(); }); $results = $dispatcher->config(); }}} {{{ use lithium\analysis\parser\Mock as ParserMock; $code = 'echo "foobar";'; ParserMock::applyFilter('config', function($self, $params, $chain) { return array(); }); $tokens = ParserMock::tokenize($code, array('wrap' => true)); }}}
Esempio n. 1
0
 public function testCallStaticCallsCorrectFunction()
 {
     NewrelicMock::applyFilter('shouldRun', function ($self, $params, $chain) {
         return true;
     });
     Mocker::overwriteFunction('li3_newrelic\\extensions\\call_user_func_array', function ($function_name) {
         return $function_name;
     });
     $result = NewrelicMock::custom_metric();
     $this->assertIdentical('newrelic_custom_metric', $result);
 }
Esempio n. 2
0
 public function tearDown()
 {
     Mocker::overwriteFunction(false);
 }
Esempio n. 3
0
 public function testEmailDomainCheckBadMxrr()
 {
     Mocker::overwriteFunction('lithium\\util\\getmxrr', function ($host, &$mxhosts) {
         $mxhosts = array();
         return true;
     });
     $this->assertTrue(Validator::isEmail('*****@*****.**', null, array('deep' => true)));
 }
Esempio n. 4
0
 public function testRespondsToMagic()
 {
     $chain = Mocker::chain(array());
     $this->assertTrue($chain->respondsTo('gt'));
     $this->assertTrue($chain->respondsTo('lt'));
     $this->assertFalse($chain->respondsTo('et'));
 }
Esempio n. 5
0
 public function testMagicCallGetStoredResultsWhenCalledIndirectly()
 {
     $obj = new \lithium\tests\mocks\test\mockStdClass\Mock();
     $obj->methodBar();
     $results = Mocker::mergeResults($obj->results, $obj::$staticResults);
     $this->assertArrayHasKey('__call', $results);
     $this->assertCount(2, $results['__call']);
 }
Esempio n. 6
0
 public function testNotCreateCacheWhenTestingEnabled()
 {
     $adapter = 'lithium\\tests\\mocks\\core\\mockAdapter\\Mock';
     $adapter::config(array('default' => array(array('adapter' => 'Memory'))));
     $adapter::enabled('default');
     $chain = Mocker::chain($adapter);
     $this->assertFalse($chain->called('adapter')->success());
 }
 public function testChainReturnsMockerChain()
 {
     $this->assertTrue(Mocker::chain(new \stdClass()) instanceof \lithium\test\MockerChain);
 }
Esempio n. 8
0
 public function testRead()
 {
     $this->_createObjects();
     $this->charizard->connection->applyFilter('get', function () {
         return json_encode(array('responseHeader' => array('status' => 0), 'grouped' => array('master_id' => array('matches' => 1234, 'ngroups' => 5678, 'groups' => array('foo', 'bar', 'baz')))));
     });
     $this->charizard->read($this->query);
     $this->assertTrue(Mocker::chain($this->charizard)->called('item')->with(null, array('foo', 'bar', 'baz'), array('stats' => array('matches' => 1234, 'ngroups' => 5678, 'count' => 5678, 'facet_counts' => array(), 'facets' => array()), 'class' => 'set'))->eq(1)->success());
 }
Esempio n. 9
0
 public function testInstallDocsWithGit()
 {
     $base = 'lithium\\console\\command\\';
     Mocker::overwriteFunction("{$base}shell_exec", function ($cmd) {
         if ($cmd === 'git --version') {
             return 'git version 1.7.9.5';
         }
         return true;
     });
     Mocker::overwriteFunction("{$base}is_dir", function ($dir) {
         return true;
     });
     $this->library->path = $this->_testPath;
     $result = $this->library->install('li3_docs');
     $this->assertTrue($result);
     $this->_cleanUp();
 }
Esempio n. 10
0
 public function testCannotCreateNonStandardMockClass()
 {
     $mockee = 'lithium\\console\\request\\Mocker';
     Mocker::create($mockee);
     $this->assertTrue(!class_exists($mockee));
 }
Esempio n. 11
0
 public function setup()
 {
     Mocker::register();
 }