浏览代码

More tests.

euromark 11 年之前
父节点
当前提交
1674f7914b

+ 1 - 0
docs/README.md

@@ -16,6 +16,7 @@ This cake3 branch only works for **CakePHP3.x** - please use the master branch f
 * [Behavior/Passwordable](Behavior/Passwordable.md)
 * [Behavior/Passwordable](Behavior/Passwordable.md)
 * [Behavior/Slugged](Behavior/Slugged.md)
 * [Behavior/Slugged](Behavior/Slugged.md)
 * [Behavior/Reset](Behavior/Reset.md)
 * [Behavior/Reset](Behavior/Reset.md)
+* [Component/Flash](Component/Flash.md)
 * [View/Rss](View/Rss.md)
 * [View/Rss](View/Rss.md)
 * ...
 * ...
 * [Testing](TestSuite/Testing.md)
 * [Testing](TestSuite/Testing.md)

+ 18 - 1
docs/TestSuite/Testing.md

@@ -6,7 +6,7 @@ Let's you test even faster.
 
 
 This trait adds the following methods to your test suite:
 This trait adds the following methods to your test suite:
 
 
-### _osFix()
+### osFix()
 
 
 In case you need to format certain os specific files to "\n" before comparing
 In case you need to format certain os specific files to "\n" before comparing
 them as strings.
 them as strings.
@@ -33,6 +33,23 @@ you are currently working on or debugging:
 php phpunit.phar --filter testFooBar /path/to/SomeTest.php -vv
 php phpunit.phar --filter testFooBar /path/to/SomeTest.php -vv
 ```
 ```
 
 
+### isDebug()
+With this method you can apply additional testing code if a `--debug` flag has been set.
+
+As an example you can by default mock out some API call, but with the debug flat set use
+the real API connection (for local testing). This way you can quickly confirm that the API
+connection is not only still working in simulated (mocking) the way it used to, but also
+that it's still the real deal.
+```php
+$this->Api = new ApiClass();
+
+if (!$this->isDebug()) {
+	$this->Api = $this->getMock('ApiClass');
+	$this->Api->expects(...)->...;
+}
+```
+
+
 ## IntegrationTestCase
 ## IntegrationTestCase
 
 
 See the above trait features.
 See the above trait features.

+ 1 - 0
phpunit.xml.dist

@@ -29,6 +29,7 @@
 		</whitelist>
 		</whitelist>
 		<blacklist>
 		<blacklist>
 			<directory suffix=".ctp">./src/Template</directory>
 			<directory suffix=".ctp">./src/Template</directory>
+			<file>./src/Utility/Set.php</file>
 		</blacklist>
 		</blacklist>
 	</filter>
 	</filter>
 </phpunit>
 </phpunit>

+ 6 - 1
src/Controller/Component/Component.php

@@ -4,15 +4,20 @@ namespace Tools\Controller\Component;
 use Cake\Controller\Component as CakeComponent;
 use Cake\Controller\Component as CakeComponent;
 
 
 /**
 /**
+ * Convenience class that automatically provides the component's methods with
+ * the controller instance via `$this->Controller`.
  */
  */
 class Component extends CakeComponent {
 class Component extends CakeComponent {
 
 
+	/**
+	 * @var \Cake\Controller\Controller
+	 */
 	public $Controller;
 	public $Controller;
 
 
 	/**
 	/**
 	 * Component::beforeFilter()
 	 * Component::beforeFilter()
 	 *
 	 *
-	 * @param Event $event
+	 * @param \Cake\Event\Event $event
 	 * @return void
 	 * @return void
 	 */
 	 */
 	public function beforeFilter(Event $event) {
 	public function beforeFilter(Event $event) {

+ 4 - 3
src/TestSuite/TestCase.php

@@ -12,7 +12,7 @@ abstract class TestCase extends CakeTestCase {
 	use ToolsTestTrait;
 	use ToolsTestTrait;
 
 
 	/**
 	/**
-	 * Opposite wrapper method of assertWithinMargin.
+	 * Opposite wrapper method of assertWithinRange().
 	 *
 	 *
 	 * @param float $result
 	 * @param float $result
 	 * @param float $expected
 	 * @param float $expected
@@ -20,10 +20,11 @@ abstract class TestCase extends CakeTestCase {
 	 * @param string $message
 	 * @param string $message
 	 * @return void
 	 * @return void
 	 */
 	 */
-	protected static function assertNotWithinMargin($result, $expected, $margin, $message = '') {
+	protected static function assertNotWithinRange($expected, $result, $margin, $message = '') {
 		$upper = $result + $margin;
 		$upper = $result + $margin;
 		$lower = $result - $margin;
 		$lower = $result - $margin;
-		return static::assertFalse((($expected <= $upper) && ($expected >= $lower)), $message);
+
+		return static::assertTrue((($expected > $upper) || ($expected < $lower)), $message);
 	}
 	}
 
 
 }
 }

+ 47 - 0
tests/TestCase/Controller/ControllerTest.php

@@ -0,0 +1,47 @@
+<?php
+namespace Tools\Test\TestCase\Controller;
+
+use Cake\Controller\ComponentRegistry;
+use Cake\Controller\Component;
+use Cake\Controller\Component\CommonComponent;
+use Cake\Core\Configure;
+use Cake\Network\Request;
+use Cake\Network\Session;
+use Cake\TestSuite\TestCase;
+use Tools\Controller\Controller;
+
+/**
+ */
+class ControllerTest extends TestCase {
+
+	public $Controller;
+
+	public function setUp() {
+		parent::setUp();
+
+		Configure::write('App.namespace', 'TestApp');
+
+		$this->Controller = new Controller();
+		$this->Controller->startupProcess();
+	}
+
+	public function tearDown() {
+		parent::tearDown();
+
+		unset($this->Controller);
+	}
+
+	/**
+	 * CommonComponentTest::testLoadComponent()
+	 *
+	 * @return void
+	 */
+	public function testDisableCache() {
+		$this->Controller->disableCache();
+
+		$result = $this->Controller->response->header();
+		$expected = array('Pragma', 'Expires', 'Last-Modified', 'Cache-Control');
+		$this->assertSame($expected, array_keys($result));
+	}
+
+}

+ 27 - 0
tests/TestCase/TestSuite/TestCaseTest.php

@@ -0,0 +1,27 @@
+<?php
+namespace Tools\TestCase\TestSuite;
+
+use Tools\TestSuite\TestCase;
+
+class TestCaseTest extends TestCase {
+
+	public $TestCase;
+
+	public function setUp() {
+		parent::setUp();
+	}
+
+	public function tearDown() {
+		parent::tearDown();
+	}
+
+	/**
+	 * @return void
+	 */
+	public function testAssertNotWithinRange() {
+		$this->assertWithinRange(22, 23, 1);
+
+		$this->assertNotWithinRange(22, 23, 0.9);
+	}
+
+}