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)); }}}
コード例 #1
0
ファイル: NewrelicTest.php プロジェクト: mdx-dev/li3_newrelic
 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);
 }
コード例 #2
0
ファイル: ContextTest.php プロジェクト: nilamdoc/KYCGlobal
 public function tearDown()
 {
     Mocker::overwriteFunction(false);
 }
コード例 #3
0
ファイル: ValidatorTest.php プロジェクト: nilamdoc/KYCGlobal
 public function testEmailDomainCheckBadMxrr()
 {
     Mocker::overwriteFunction('lithium\\util\\getmxrr', function ($host, &$mxhosts) {
         $mxhosts = array();
         return true;
     });
     $this->assertTrue(Validator::isEmail('*****@*****.**', null, array('deep' => true)));
 }
コード例 #4
0
ファイル: MockerChainTest.php プロジェクト: fedeisas/lithium
 public function testRespondsToMagic()
 {
     $chain = Mocker::chain(array());
     $this->assertTrue($chain->respondsTo('gt'));
     $this->assertTrue($chain->respondsTo('lt'));
     $this->assertFalse($chain->respondsTo('et'));
 }
コード例 #5
0
ファイル: MockerTest.php プロジェクト: nilamdoc/KYCGlobal
 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']);
 }
コード例 #6
0
ファイル: AdaptableTest.php プロジェクト: fedeisas/lithium
 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());
 }
コード例 #7
0
 public function testChainReturnsMockerChain()
 {
     $this->assertTrue(Mocker::chain(new \stdClass()) instanceof \lithium\test\MockerChain);
 }
コード例 #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());
 }
コード例 #9
0
ファイル: LibraryTest.php プロジェクト: nilamdoc/KYCGlobal
 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();
 }
コード例 #10
0
 public function testCannotCreateNonStandardMockClass()
 {
     $mockee = 'lithium\\console\\request\\Mocker';
     Mocker::create($mockee);
     $this->assertTrue(!class_exists($mockee));
 }
コード例 #11
0
 public function setup()
 {
     Mocker::register();
 }