Skip to content

Commit

Permalink
Remove deprecated test of internal attributes via assertAttributeEquals
Browse files Browse the repository at this point in the history
See sebastianbergmann/phpunit#3339 (comment)

It is seen as bad practice to test internal stuff of objects instead of the actual input and output of mathod calls.

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
  • Loading branch information
MorrisJobke committed Jul 30, 2020
1 parent 9906950 commit 4290572
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
24 changes: 9 additions & 15 deletions tests/lib/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ public function testGetValueReturnsEnvironmentValueIfSetToFalse() {

public function testSetValue() {
$this->config->setValue('foo', 'moo');
$expectedConfig = $this->initialConfig;
$expectedConfig['foo'] = 'moo';
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$this->assertSame('moo', $this->config->getValue('foo'));

$content = file_get_contents($this->configFile);
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .
" 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n 'alcohol_free' => false,\n);\n";
$this->assertEquals($expected, $content);

$this->config->setValue('bar', 'red');
$this->config->setValue('apps', array('files', 'gallery'));
$expectedConfig['bar'] = 'red';
$expectedConfig['apps'] = array('files', 'gallery');
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$this->config->setValue('apps', ['files', 'gallery']);
$this->assertSame('red', $this->config->getValue('bar'));
$this->assertSame(['files', 'gallery'], $this->config->getValue('apps'));

$content = file_get_contents($this->configFile);

Expand All @@ -105,18 +102,17 @@ public function testSetValues() {
'not_exists' => null,
]);

$this->assertAttributeEquals($this->initialConfig, 'cache', $this->config);
$this->assertSame('bar', $this->config->getValue('foo'));
$this->assertSame(null, $this->config->getValue('not_exists'));
$content = file_get_contents($this->configFile);
$this->assertEquals(self::TESTCONTENT, $content);

$this->config->setValues([
'foo' => 'moo',
'alcohol_free' => null,
]);
$expectedConfig = $this->initialConfig;
$expectedConfig['foo'] = 'moo';
unset($expectedConfig['alcohol_free']);
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$this->assertSame('moo', $this->config->getValue('foo'));
$this->assertSame(null, $this->config->getValue('not_exists'));

$content = file_get_contents($this->configFile);
$expected = "<?php\n\$CONFIG = array (\n 'foo' => 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .
Expand All @@ -126,9 +122,7 @@ public function testSetValues() {

public function testDeleteKey() {
$this->config->deleteKey('foo');
$expectedConfig = $this->initialConfig;
unset($expectedConfig['foo']);
$this->assertAttributeEquals($expectedConfig, 'cache', $this->config);
$this->assertSame('this_was_clearly_not_set_before', $this->config->getValue('foo', 'this_was_clearly_not_set_before'));
$content = file_get_contents($this->configFile);

$expected = "<?php\n\$CONFIG = array (\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " .
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/DB/DBSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public function doTestSchemaDumping() {
$outfile = $this->tempManager->getTemporaryFile();
OC_DB::getDbStructure($outfile);
$content = file_get_contents($outfile);
$this->assertContains($this->table1, $content);
$this->assertContains($this->table2, $content);
$this->assertStringContainsString($this->table1, $content);
$this->assertStringContainsString($this->table2, $content);
}

public function doTestSchemaRemoving() {
Expand Down

0 comments on commit 4290572

Please sign in to comment.