Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed May 12, 2019
1 parent 7449cbe commit 31fc1f7
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 27 deletions.
Expand Up @@ -31,7 +31,7 @@ public function setUp(): void {

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);
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -86,10 +86,11 @@ public function testFrom() {
}

/**
* @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']);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Utility/NumberTest.php
Expand Up @@ -169,7 +169,7 @@ public function testRoundTo() {
];
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 = [
Expand All @@ -182,7 +182,7 @@ public function testRoundTo() {
];
foreach ($values2 as $was => $expected) {
$is = Number::roundTo($was, 0.1);
$this->assertSame($expected, $is, null, $was);
$this->assertSame($expected, $is, $was);
}
}

Expand All @@ -201,7 +201,7 @@ public function testRoundUpTo() {
];
foreach ($values as $was => $expected) {
$is = Number::roundUpTo($was, 10);
$this->assertSame($expected, $is, null, $was);
$this->assertSame($expected, $is, $was);
}
//increment = 5
$values = [
Expand All @@ -214,7 +214,7 @@ public function testRoundUpTo() {
];
foreach ($values as $was => $expected) {
$is = Number::roundUpTo($was, 5);
$this->assertSame($expected, $is, null, $was);
$this->assertSame($expected, $is, $was);
}
}

Expand All @@ -233,7 +233,7 @@ public function testRoundDownTo() {
];
foreach ($values as $was => $expected) {
$is = Number::roundDownTo($was, 10);
$this->assertSame($expected, $is, null, $was);
$this->assertSame($expected, $is, $was);
}
//increment = 3
$values = [
Expand All @@ -246,7 +246,7 @@ public function testRoundDownTo() {
];
foreach ($values as $was => $expected) {
$is = Number::roundDownTo($was, 3);
$this->assertSame($expected, $is, null, $was);
$this->assertSame($expected, $is, $was);
}
}

Expand All @@ -263,8 +263,8 @@ public function testGetDecimalPlaces() {
'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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/Utility/UtilityTest.php
Expand Up @@ -458,14 +458,16 @@ public function testExpandList() {
}

/**
* @expectedException \RuntimeException
* @return void
*/
public function testExpandListWithKeyLessListInvalid() {
$is = [
'Some',
'ValueOnly',
];

$this->expectException(\RuntimeException::class);

Utility::expandList($is);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Expand Up @@ -6,7 +6,7 @@
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);
Expand Down
21 changes: 21 additions & 0 deletions 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;
}

}
11 changes: 6 additions & 5 deletions tests/test_app/Controller/CommonComponentTestController.php
Expand Up @@ -10,14 +10,15 @@
*/
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');
}

}
12 changes: 6 additions & 6 deletions tests/test_app/Controller/MobileComponentTestController.php
Expand Up @@ -8,11 +8,11 @@
*/
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');
}

}
9 changes: 5 additions & 4 deletions tests/test_app/Controller/UrlComponentTestController.php
Expand Up @@ -10,9 +10,10 @@
*/
class UrlComponentTestController extends Controller {

/**
* @var array
*/
public $components = ['Tools.Url'];
public function initialize(): void {
parent::initialize();

$this->loadComponent('Tools.Url');
}

}

0 comments on commit 31fc1f7

Please sign in to comment.