Skip to content

Comments

Refactors test suite to run with vanilla PHPUnit runner#2

Open
garethellis36 wants to merge 5 commits intomasterfrom
remove-cake-test-runner
Open

Refactors test suite to run with vanilla PHPUnit runner#2
garethellis36 wants to merge 5 commits intomasterfrom
remove-cake-test-runner

Conversation

@garethellis36
Copy link

No description provided.

/**
* @var array|int[]|mixed
*/
private $_cacheDisable;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property is added in a few test classes because I was getting warnings about it not being present before I had fixed the error-handling. It doesn't actually need to be there for the tests to pass but it also doesn't hurt to clean this up I guess.


foreach ($servers as $server) {
list($host, $port) = explode(':', $server);
[$host, $port] = explode(':', $server);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naughty IntelliJ

public $records = array(
array('username' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'),
array('username' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
array('username' => 'nate', 'password' => '5f4dcc3b5aa765d61Cakd8327deb882cf99', 'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell what changed here.

$level = ob_get_level();

if (!empty($this->fixtureManager)) {
$this->fixtureManager->load($this);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff is now done in the setUp() method

}
$result = parent::run($result);
if (!empty($this->fixtureManager)) {
$this->fixtureManager->unload($this);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now done in tearDown()

}

for ($i = ob_get_level(); $i < $level; ++$i) {
ob_start();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what this ob_* stuff was for, but deleting it doesn't break anything. Cake also has a browser test runner, so it might have been for that.

* @param string $method Test method about that was executed.
* @return void
*/
public function endTest($method) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods did literally nothing. They're not overriding a parent method or anything.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are there to be overridden aren't they? Like abstract methods but they don't need to be implemented.


if (!empty($this->fixtures)) {
$this->fixtureManager = $this->fixtureManager ?? CakeFixtureManager::getInstance();
$this->fixtureManager->fixturize($this);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixturize() step was done inside CakeTestRunner before. The fixturize() method has checks already in place to make sure it doesn't do duplicate work.

* @param bool $reset to set new static timestamp.
* @return int timestamp
*/
public static function time($reset = false) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously in CakeTestSuiteDispatcher.

parent::assertPostConditions();
$this->endTest($this->getName());
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parent methods of these did absolutely nothing. I guess they did something once upon a time!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are removing CakeTestCase functionality here but removing the 'startTest' and 'endTest' methods being called. I imagine you have done this deliberately, but since you haven't said that anywhere, I am pointing it out.


public function __destruct()
{
$this->shutDown();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit gross but it's the only way I could find to call the shutDown() method at the end of the test run.

@@ -1,3 +1,42 @@
<?php

exec(__DIR__ . "/tests");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sure all the right tmp dirs are present and have the correct permissions

restore_exception_handler();

// freeze the time
CakeTestCase::time();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously done with a call to static::time() inside CakeTestSuiteDispatcher right before it started the test suite.


ini_set("memory_limit", "512M");

define("TMP", "/home/vagrant/caketmp/");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cake doesn't have a way of configuring the path to the temp directory, so we have to set this constant before it can. We need to change the temp directory to be a folder which is not shared with the host OS, or the permissions-related tests will not pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants