Browse files

Replacing the usage of PHPUnit static mock on App::classname()

  • Loading branch information...
1 parent 64ad0e4 commit 36dee4ccf833d0d5a8a3df5d61869eb2df751d4e @jrbasso jrbasso committed Mar 11, 2014
Showing with 29 additions and 15 deletions.
  1. +13 −15 tests/TestCase/Core/AppTest.php
  2. +16 −0 tests/test_app/TestApp/Core/TestApp.php
View
28 tests/TestCase/Core/AppTest.php
@@ -19,6 +19,7 @@
use Cake\Core\Configure;
use Cake\Core\Plugin;
use Cake\TestSuite\TestCase;
+use TestApp\Core\TestApp;
/**
* AppTest class
@@ -46,21 +47,18 @@ public function tearDown() {
*/
public function testClassname($class, $type, $suffix = '', $existsInBase = false, $expected = false) {
Configure::write('App.namespace', 'TestApp');
- $mock = $this->getMockClass('Cake\Core\App', ['_classExistsInBase']);
-
- $mock::staticExpects($this->at(0))
- ->method('_classExistsInBase')
- ->will($this->returnValue($existsInBase));
-
- $checkCake = (!$existsInBase || strpos('.', $class));
- if ($checkCake) {
- $existsInCake = (bool)$expected;
- $mock::staticExpects($this->at(1))
- ->method('_classExistsInBase')
- ->will($this->returnValue($existsInCake));
- }
-
- $return = $mock::classname($class, $type, $suffix);
+ $i = 0;
+ TestApp::$existsInBaseCallback = function($name, $namespace) use ($existsInBase, $class, $expected, &$i) {
+ if ($i++ === 0) {
+ return $existsInBase;
+ }
+ $checkCake = (!$existsInBase || strpos('.', $class));
+ if ($checkCake) {
+ return (bool)$expected;
+ }
+ return false;
+ };
+ $return = TestApp::classname($class, $type, $suffix);
$this->assertSame($expected, $return);
}
View
16 tests/test_app/TestApp/Core/TestApp.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace TestApp\Core;
+
+use Cake\Core\App;
+
+class TestApp extends App {
+
+ public static $existsInBaseCallback;
+
+ protected static function _classExistsInBase($name, $namespace) {
+ $callback = static::$existsInBaseCallback;
+ return $callback($name, $namespace);
+ }
+
+}

0 comments on commit 36dee4c

Please sign in to comment.