Skip to content
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

Improve assertion and ignore cached PHPUnit file #462

Merged

Conversation

peter279k
Copy link
Contributor

Changed log

  • Improve some PHPUnit assertions.
  • Let the .phpunit.result.cache file be on .gitignore file and this is generated by PHPUnit 9.x. version.

@@ -17,7 +17,7 @@ public function testAddCollector()
$this->c->addCollector($c = new MockCollector());
$this->assertContains($c, $this->c->getCollectors());
$this->assertEquals($c, $this->c['mock']);
$this->assertTrue(isset($this->c['mock']));
$this->assertArrayHasKey('mock', $this->c);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertArrayHasKey to assert the expected key is on the result array.

@@ -33,16 +33,16 @@ public function testStartStopMeasure()
$this->assertEquals('bar', $m[0]['label']);
$this->assertEquals('baz', $m[0]['collector']);
$this->assertEquals(array('bar' => 'baz'), $m[0]['params']);
$this->assertTrue($m[0]['start'] < $m[0]['end']);
$this->assertLessThan($m[0]['end'], $m[0]['start']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertLessThan to assert expected and result comparison.

$this->assertTrue($data['end'] > $this->s);
$this->assertTrue($data['duration'] > 0);
$this->assertGreaterThan($this->s, $data['end']);
$this->assertGreaterThan(0, $data['duration']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertGreaterThan to assert expected and result comparison.

@@ -96,7 +96,7 @@ public function testStackedData()
$data = $this->debugbar->getStackedData();
$this->assertArrayNotHasKey($ns, $http->session);
$this->assertArrayHasKey($id, $data);
$this->assertEquals(1, count($data));
$this->assertCount(1, $data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertCount to assert expected is same as result count.

@@ -17,13 +17,13 @@ public function setUp(): void
public function assertJsonIsArray($json)
{
$data = json_decode($json);
$this->assertTrue(is_array($data));
$this->assertIsArray($data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertIsArray to assert expected type is array type.

}

public function assertJsonIsObject($json)
{
$data = json_decode($json);
$this->assertTrue(is_object($data));
$this->assertIsObject($data);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the assertIsObject to assert expected type is object.

@barryvdh barryvdh closed this Mar 21, 2024
@barryvdh barryvdh reopened this Mar 21, 2024
@barryvdh barryvdh merged commit 6706ad4 into maximebf:master Mar 30, 2024
7 checks passed
@peter279k peter279k deleted the test_enhancement branch March 30, 2024 14:32
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.

None yet

3 participants