Skip to content

Commit

Permalink
Merge pull request #709 from cakephp/bugfix/returntype
Browse files Browse the repository at this point in the history
Fix up return types, better asserts and PHP74
  • Loading branch information
saeideng authored Nov 4, 2019
2 parents 7c39939 + f53b186 commit 1796aa7
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 50 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false
- 7.4snapshot

services:
- postgresql
Expand All @@ -26,21 +23,23 @@ matrix:
include:
- php: 7.1
env: PHPCS=1

- php: 7.1
env: CODECOVERAGE=1 DEFAULT=0

- php: 5.6
env: PREFER_LOWEST=1

allow_failures:
- php: 7.4snapshot

install:
- composer self-update
- sh -c "if [ '$PREFER_LOWEST' != '1' ]; then composer install --prefer-dist --no-interaction; fi"
- sh -c "if [ '$PREFER_LOWEST' = '1' ]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi"

before_script:
- sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi"
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi"
- phpenv rehash
- set +H

script:
- sh -c "if [ '$DEFAULT' = '1' ]; then [ "$(find . \( -path './vendor' \) -prune -o -type f \( -name '*.ctp' -o -name '*.php' \) -print0 | xargs -0 --no-run-if-empty -L1 -i'{}' php -l '{}' | grep -vc 'No syntax errors')" -eq 0 ]; fi"
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<phpunit bootstrap="tests/bootstrap.php">
<php>
<ini name="memory_limit" value="-1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="All Tests">
<directory>./tests/TestCase</directory>
<testsuite name="debug-kit">
<directory>tests/TestCase</directory>
</testsuite>
<!-- Add plugin test suites here. -->
</testsuites>

<!-- configure code coverage -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<listener class="Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
<object class="Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>
Expand Down
3 changes: 1 addition & 2 deletions src/Panel/RequestPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class RequestPanel extends DebugPanel
{

/**
* Data collection callback.
*
Expand All @@ -31,7 +30,7 @@ class RequestPanel extends DebugPanel
*/
public function shutdown(Event $event)
{
/* @var Controller $controller */
/* @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$request = $controller->request;
$this->_data = [
Expand Down
6 changes: 3 additions & 3 deletions src/Panel/RoutesPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class RoutesPanel extends DebugPanel
/**
* Get summary data for the routes panel.
*
* @return int
* @return string
*/
public function summary()
{
$appClass = Configure::read('App.namespace') . '\Application';
if (class_exists($appClass, false) && !Router::$initialized) {
return 0;
return '0';
}

$routes = array_filter(Router::routes(), function ($route) {
return (!isset($routes->defaults['plugin'])) || $route->defaults['plugin'] !== 'DebugKit';
});

return count($routes);
return (string)count($routes);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Cache/Engine/DebugEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public function testProxyMethodsTracksMetrics()
$this->engine->decrement('key');

$result = $this->engine->metrics();
$this->assertEquals(3, $result['write']);
$this->assertEquals(1, $result['delete']);
$this->assertEquals(1, $result['read']);
$this->assertSame(3, $result['write']);
$this->assertSame(1, $result['delete']);
$this->assertSame(1, $result['read']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/ToolbarControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testClearCacheNoGet()
{
$this->get('/debug_kit/toolbar/clear_cache?name=testing');

$this->assertEquals(405, $this->_response->getStatusCode());
$this->assertSame(405, $this->_response->getStatusCode());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Database/Log/DebugLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function testLog()

$this->logger->log($query);
$this->assertCount(1, $this->logger->queries());
$this->assertEquals(10, $this->logger->totalTime());
$this->assertEquals(5, $this->logger->totalRows());
$this->assertSame(10, $this->logger->totalTime());
$this->assertSame(5, $this->logger->totalRows());

$this->logger->log($query);
$this->assertCount(2, $this->logger->queries());
$this->assertEquals(20, $this->logger->totalTime());
$this->assertEquals(10, $this->logger->totalRows());
$this->assertSame(20, $this->logger->totalTime());
$this->assertSame(10, $this->logger->totalRows());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/DebugTimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testNestedAnonymousTimers()
$this->assertTrue(DebugTimer::stop());

$timers = DebugTimer::getAll();
$this->assertEquals(3, count($timers), 'incorrect number of timers %s');
$this->assertSame(3, count($timers), 'incorrect number of timers %s');
$firstTimerLine = __LINE__ - 9;
$secondTimerLine = __LINE__ - 8;
$file = Debugger::trimPath(__FILE__);
Expand Down Expand Up @@ -129,7 +129,7 @@ public function testRepeatTimers()
DebugTimer::stop('my timer');

$timers = DebugTimer::getAll();
$this->assertEquals(3, count($timers), 'wrong timer count %s');
$this->assertSame(3, count($timers), 'wrong timer count %s');

$this->assertTrue(isset($timers['my timer']));
$this->assertTrue(isset($timers['my timer #2']));
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Middleware/DebugKitMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testInvokeSaveData()
$this->assertEquals('/articles', $result->url);
$this->assertNotEmpty($result->requested_at);
$this->assertNotEmpty('text/html', $result->content_type);
$this->assertEquals(200, $result->status_code);
$this->assertSame(200, $result->status_code);
$this->assertGreaterThan(1, $result->panels);

$this->assertEquals('SqlLog', $result->panels[11]->panel);
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testInvokeNoModifyBinaryResponse()
$requests = TableRegistry::get('DebugKit.Requests');
$total = $requests->find()->where(['url' => '/articles'])->count();

$this->assertEquals(1, $total, 'Should track response');
$this->assertSame(1, $total, 'Should track response');
$body = $result->getBody();
$this->assertNotContains('__debug_kit', '' . $body);
$this->assertNotContains('<script', '' . $body);
Expand Down Expand Up @@ -182,7 +182,7 @@ public function testInvokeNoModifyNonHtmlResponse()
$requests = TableRegistry::get('DebugKit.Requests');
$total = $requests->find()->where(['url' => '/articles'])->count();

$this->assertEquals(1, $total, 'Should track response');
$this->assertSame(1, $total, 'Should track response');
$body = $result->getBody();
$this->assertSame('OK', '' . $body);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public function testInvokeNoModifyRequestAction()
$requests = TableRegistry::get('DebugKit.Requests');
$total = $requests->find()->where(['url' => '/articles'])->count();

$this->assertEquals(0, $total, 'Should not track sub-requests');
$this->assertSame(0, $total, 'Should not track sub-requests');
$body = $result->getBody();
$this->assertNotContains('<script', '' . $body);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Model/Table/RequestTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testFindRecent()
{
$table = TableRegistry::get('DebugKit.Requests');
$query = $table->find('recent');
$this->assertEquals(10, $query->clause('limit'));
$this->assertSame(10, $query->clause('limit'));
$this->assertNotEmpty($query->clause('order'));
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Panel/DeprecationsPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public function testShutdown()

public function testSummary()
{
$this->assertEquals(3, $this->panel->summary());
$this->assertEquals('3', $this->panel->summary());
}
}
8 changes: 4 additions & 4 deletions tests/TestCase/Panel/LogPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public function testData()
$result = $this->panel->data();

$this->assertArrayHasKey('logger', $result);
/* @var DebugKitLog $logger */
/* @var \DebugKit\Log\Engine\DebugKitLog $logger */
$logger = $result['logger'];

$this->assertInstanceOf('DebugKit\Log\Engine\DebugKitLog', $logger);
$this->assertInstanceOf(DebugKitLog::class, $logger);
$this->assertCount(1, $logger->all()['error']);
}

Expand All @@ -94,10 +94,10 @@ public function testSummary()
$this->panel->initialize();

Log::write('error', 'Test');
$this->assertEquals(1, $this->panel->summary());
$this->assertSame('1', $this->panel->summary());

Log::write('error', 'Test 2');
Log::write('notice', 'A thing');
$this->assertEquals(3, $this->panel->summary());
$this->assertSame('3', $this->panel->summary());
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/Panel/RoutesPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function setUp()
public function testSummary()
{
$this->panel->initialize();
$this->assertEquals(4, $this->panel->summary());
$this->assertSame('4', $this->panel->summary());

Router::connect('/test', ['controller' => 'Pages', 'action' => 'display', 'home']);
$this->assertEquals(5, $this->panel->summary());
$this->assertSame('5', $this->panel->summary());
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Routing/Filter/DebugBarFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testAfterDispatchSavesData()
$this->assertEquals('/articles', $result->url);
$this->assertNotEmpty($result->requested_at);
$this->assertNotEmpty('text/html', $result->content_type);
$this->assertEquals(200, $result->status_code);
$this->assertSame(200, $result->status_code);
$this->assertGreaterThan(1, $result->panels);

$this->assertEquals('SqlLog', $result->panels[11]->panel);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ToolbarServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function testSaveData()
$this->assertEquals('/articles', $result->url);
$this->assertNotEmpty($result->requested_at);
$this->assertNotEmpty('text/html', $result->content_type);
$this->assertEquals(200, $result->status_code);
$this->assertSame(200, $result->status_code);
$this->assertGreaterThan(1, $result->panels);

$this->assertEquals('SqlLog', $result->panels[11]->panel);
Expand Down

0 comments on commit 1796aa7

Please sign in to comment.