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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.lock
/vendor
/src/DebugBar/Resources/vendor
/demo/bridge/*/vendor
/src/DebugBar/Resources/vendor
.phpunit.result.cache
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

public function testCollect()
Expand Down
8 changes: 4 additions & 4 deletions tests/DebugBar/Tests/DataCollector/TimeDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

public function testCollect()
{
$this->c->addMeasure('foo', 0, 10);
$this->c->addMeasure('bar', 10, 20);
$data = $this->c->collect();
$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.

$this->assertCount(2, $data['measures']);
}

Expand All @@ -54,7 +54,7 @@ public function testMeasure()
$m = $this->c->getMeasures();
$this->assertCount(1, $m);
$this->assertEquals('bar', $m[0]['label']);
$this->assertTrue($m[0]['start'] < $m[0]['end']);
$this->assertLessThan($m[0]['end'], $m[0]['start']);
$this->assertSame('returnedValue', $returned);
}
}
6 changes: 3 additions & 3 deletions tests/DebugBar/Tests/DebugBarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function testArrayAccess()
{
$this->debugbar->addCollector($c = new MockCollector());
$this->assertEquals($c, $this->debugbar['mock']);
$this->assertTrue(isset($this->debugbar['mock']));
$this->assertFalse(isset($this->debugbar['foo']));
$this->assertArrayHasKey('mock', $this->debugbar);
$this->assertArrayNotHasKey('foo', $this->debugbar);
}

public function testStorage()
Expand Down Expand Up @@ -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.

$this->assertArrayHasKey('mock', $data[$id]);
$this->assertEquals($c->collect(), $data[$id]['mock']);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/DebugBar/Tests/DebugBarTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}

public function assertJsonArrayNotEmpty($json)
Expand Down