Browse Source

Fix tests.

mscherer 6 years ago
parent
commit
31fc1f7a0c

+ 1 - 1
tests/TestCase/Controller/Component/CommonComponentTest.php

@@ -31,7 +31,7 @@ class CommonComponentTest extends TestCase {
 
 		Configure::write('App.fullBaseUrl', 'http://localhost');
 
-		$this->request = new ServerRequest('/my_controller/foo');
+		$this->request = new ServerRequest(['url' => '/my_controller/foo']);
 		$this->request = $this->request->withParam('controller', 'MyController')
 			->withParam('action', 'foo');
 		$this->Controller = new CommonComponentTestController($this->request);

+ 2 - 1
tests/TestCase/Mailer/EmailTest.php

@@ -86,10 +86,11 @@ class EmailTest extends TestCase {
 	}
 
 	/**
-	 * @expectedException \InvalidArgumentException
 	 * @return void
 	 */
 	public function testFromExecption() {
+		$this->expectException(\InvalidArgumentException::class);
+
 		$this->Email->setFrom(['cake@cakephp.org' => 'CakePHP', 'fail@cakephp.org' => 'From can only be one address']);
 	}
 

+ 8 - 8
tests/TestCase/Utility/NumberTest.php

@@ -169,7 +169,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values as $was => $expected) {
 			$is = Number::roundTo($was, 10);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 		//increment = 0.1
 		$values2 = [
@@ -182,7 +182,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values2 as $was => $expected) {
 			$is = Number::roundTo($was, 0.1);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 	}
 
@@ -201,7 +201,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values as $was => $expected) {
 			$is = Number::roundUpTo($was, 10);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 		//increment = 5
 		$values = [
@@ -214,7 +214,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values as $was => $expected) {
 			$is = Number::roundUpTo($was, 5);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 	}
 
@@ -233,7 +233,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values as $was => $expected) {
 			$is = Number::roundDownTo($was, 10);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 		//increment = 3
 		$values = [
@@ -246,7 +246,7 @@ class NumberTest extends TestCase {
 		];
 		foreach ($values as $was => $expected) {
 			$is = Number::roundDownTo($was, 3);
-			$this->assertSame($expected, $is, null, $was);
+			$this->assertSame($expected, $is, $was);
 		}
 	}
 
@@ -263,8 +263,8 @@ class NumberTest extends TestCase {
 			'0.001' => 3
 		];
 		foreach ($values as $was => $expected) {
-			$is = Number::getDecimalPlaces($was, 10);
-			$this->assertSame($expected, $is); //, null, $was
+			$is = Number::getDecimalPlaces($was);
+			$this->assertSame($expected, $is);
 		}
 	}
 

+ 3 - 1
tests/TestCase/Utility/UtilityTest.php

@@ -458,7 +458,6 @@ class UtilityTest extends TestCase {
 	}
 
 	/**
-	 * @expectedException \RuntimeException
 	 * @return void
 	 */
 	public function testExpandListWithKeyLessListInvalid() {
@@ -466,6 +465,9 @@ class UtilityTest extends TestCase {
 			'Some',
 			'ValueOnly',
 		];
+
+		$this->expectException(\RuntimeException::class);
+
 		Utility::expandList($is);
 	}
 

+ 1 - 1
tests/bootstrap.php

@@ -6,7 +6,7 @@ if (!defined('DS')) {
 	define('DS', DIRECTORY_SEPARATOR);
 }
 if (!defined('WINDOWS')) {
-	if (DS == '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
+	if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
 		define('WINDOWS', true);
 	} else {
 		define('WINDOWS', false);

+ 21 - 0
tests/test_app/Application.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App;
+
+use Cake\Http\BaseApplication;
+use Cake\Http\MiddlewareQueue;
+use Cake\Routing\Middleware\RoutingMiddleware;
+
+class Application extends BaseApplication {
+
+	/**
+	 * @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to set in your App Class
+	 * @return \Cake\Http\MiddlewareQueue
+	 */
+	public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue {
+		$middlewareQueue->add(new RoutingMiddleware($this));
+
+		return $middlewareQueue;
+	}
+
+}

+ 6 - 5
tests/test_app/Controller/CommonComponentTestController.php

@@ -13,11 +13,12 @@ class CommonComponentTestController extends Controller {
 	/**
 	 * @var array
 	 */
-	public $components = ['Tools.Common'];
-
-	/**
-	 * @var array
-	 */
 	public $autoRedirectActions = ['allowed'];
 
+	public function initialize(): void {
+		parent::initialize();
+
+		$this->loadComponent('Tools.Common');
+	}
+
 }

+ 6 - 6
tests/test_app/Controller/MobileComponentTestController.php

@@ -8,11 +8,11 @@ use Tools\Controller\Controller;
  */
 class MobileComponentTestController extends Controller {
 
-	/**
-	 * Components property
-	 *
-	 * @var array
-	 */
-	public $components = ['RequestHandler', 'Tools.Mobile'];
+	public function initialize(): void {
+		parent::initialize();
+
+		$this->loadComponent('RequestHandler');
+		$this->loadComponent('Tools.Mobile');
+	}
 
 }

+ 5 - 4
tests/test_app/Controller/UrlComponentTestController.php

@@ -10,9 +10,10 @@ use Tools\Controller\Controller;
  */
 class UrlComponentTestController extends Controller {
 
-	/**
-	 * @var array
-	 */
-	public $components = ['Tools.Url'];
+	public function initialize(): void {
+		parent::initialize();
+
+		$this->loadComponent('Tools.Url');
+	}
 
 }