-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
php 8.x compatibility #3
Comments
…ponse|null but return statement is missing" #3
…d>>) does not accept default value of type array<int, string>" #3
Continue working on fixing PHP Unit Tests Taking a look into to readme to find out about new way of launching a unit test. Inspecting the new
Continue to fix test Current run shows:
This is the version of the file I'm working on: https://github.com/the-kbA-team/cakephp-filter-plugin/blob/34c653fa21949a24daeb2cd9f639cff8baa90d7b/Test/Case/Controller/Component/FilterComponentTest.php /**
* Test loading filter data from session (both full and empty).
*/
public function testSessionStartupData(): void
{
$testSettings = array(
'index' => array(
'Document' => array(
'Document.title' => array('type' => 'text')
),
'FakeNonexistant' => array(
'drink' => array('type' => 'select')
)
)
);
$this->Controller->filters = $testSettings;
$sessionKey = sprintf('FilterPlugin.Filters.%s.%s', $this->Controller->name, $this->Controller->action);
$filterValues = array();
$this->Controller->Session->write($sessionKey, $filterValues);
try {
$this->Controller->Components->trigger('initialize', array($this->Controller));
$this->fail('InvalidArgumentException was not thrown');
} catch (InvalidArgumentException $e1) {
$this->assertSame('Filter model not found: FakeNonexistant', $e1->getMessage());
}
try {
$this->Controller->Components->trigger('startup', array($this->Controller));
$this->fail('InvalidArgumentException was not thrown');
} catch (InvalidArgumentException $e2) {
$this->assertSame('xxxFilter model not found: FakeNonexistant', $e2->getMessage());
}
$actualFilterValues = $this->Controller->Document->getFilterValues();
$this->assertEquals(
$filterValues,
$actualFilterValues[$this->Controller->Document->alias]
);
$filterValues = array('Document' => array('title' => 'in'));
$this->Controller->Session->write($sessionKey, $filterValues);
$this->Controller->Components->trigger('startup', array($this->Controller));
$actualFilterValues = $this->Controller->Document->getFilterValues();
$this->assertEquals(
$filterValues,
$actualFilterValues[$this->Controller->Document->alias]
);
$this->Controller->Session->delete($sessionKey);
} This unit test works with session data and I just found out that the values are not saved. I did var_dump($this->Controller->Session->write($sessionKey, $filterValues)); and the resulting output on the console was
which means that the data could not be saved as seen in /**
* Writes value to given session variable name.
*
* @param string|array $name Name of variable
* @param mixed $value Value to write
* @return bool True if the write was successful, false if the write failed
*/
public static function write($name, $value = null) {
if (!static::start()) {
return false;
}
$write = $name;
if (!is_array($name)) {
$write = array($name => $value);
}
foreach ($write as $key => $val) {
static::_overwrite($_SESSION, Hash::insert($_SESSION, $key, $val));
if (Hash::get($_SESSION, $key) !== $val) {
return false;
}
}
return true;
} At this point manually debugging gets I try to talk to Martin Mitterhauser to get some ideas. Didn't reach him. Had the idea to look into the CakePHP Cookbook and I found something!
I looked into the Github testing workflow of the CakePHP2 Fork we are using. The call to PHPUnit looks like this:
It looks like that this argument can also be defined in the phpunit.xml configuration: https://docs.phpunit.de/en/9.6/configuration.html#the-stderr-attribute I added the stderr attribute to our phpunit.xml.dist: the-kbA-team/cake2-app-template@b99bc71 Yes!! Session works now: var_dump($this->Controller->Session->write($sessionKey, $filterValues)); and the resulting output on the console was
I was able to fix the testSessionStartupData() as far as I understand what should be tested (1e27ad6) Current run shows (
Working on Current output is:
I was able to fix testNoModelFound() as far as I understand what should be tested (ce74bd0) Current run shows (
Now there is only 1 assertion that fails in FilterComponentTest.php:
The unit test fails because FilterComponent->startup() returns early here
It has to be investigated further what is wrong here, it should not return early. That's it for today. @gregor-j See above what I did today |
Continuing where I left off, the unit test for FilterComponent is not done. The unit test "testCustomSelector" still fails.
It seems that there must be a model I found the Let's see what I have to do to get unit test to use this class. |
Fixing them would not improve code quality
No description provided.
The text was updated successfully, but these errors were encountered: