Skip to content
Permalink
Browse files

modified unittests for PhpUnitResult and PluginResult classes

- combined tests using dataprovider
- added tests for new PluginClass
  • Loading branch information...
Mathias Kühn authored and corpsee committed Aug 6, 2019
1 parent 7b63bd3 commit eef6f16266b9ae338e82e74a4a3618ed9a47464b
@@ -13,4 +13,9 @@ public function isDegraded()
{
return $this->right < $this->left;
}
protected function getTaskDescriptionMessage()
{
return 'pls fix %s because the coverage has decreased from %d to %d';
}
}
@@ -86,13 +86,18 @@ public function generateTaskDescription()
}
return sprintf(
'pls fix %s because it has increased from %d to %d errors',
$this->getTaskDescriptionMessage(),
$this->plugin,
$this->left,
$this->right
);
}
protected function getTaskDescriptionMessage()
{
return 'pls fix %s because it has increased from %d to %d errors';
}
public function __toString()
{
return $this->plugin;
@@ -0,0 +1,82 @@
<?php
namespace PHPCensor\Plugin\Util;
use PHPUnit\Framework\TestCase;
class BitbucketNotifyPhpUnitResultTest extends TestCase
{
public function dataProvider()
{
return [
'unchanged' => [
[
'test', 0, 0,
],
[
'unchanged' => true,
'improved' => false,
'degraded' => false,
'string' => 'test',
'formattedOutput' => "test | 0\t=> 0",
'taskDescription' => '',
]
],
'unchangedWithFail' => [
[
'test', 1, 1,
],
[
'unchanged' => true,
'improved' => false,
'degraded' => false,
'string' => 'test',
'formattedOutput' => "test | 1\t=> 1\tpls improve me :-(",
'taskDescription' => '',
]
],
'improved' => [
[
'test', 0, 1,
],
[
'unchanged' => false,
'improved' => true,
'degraded' => false,
'string' => 'test',
'formattedOutput' => "test | 0\t=> 1\tgreat success!",
'taskDescription' => '',
]
],
'degraded' => [
[
'test', 1, 0,
],
[
'unchanged' => false,
'improved' => false,
'degraded' => true,
'string' => 'test',
'formattedOutput' => "test | 1\t=> 0\t!!!!! o_O",
'taskDescription' => 'pls fix test because the coverage has decreased from 1 to 0',
]
],
];
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testFormating(array $input, array $expected)
{
$pluginResult = new BitbucketNotifyPhpUnitResult($input[0], $input[1], $input[2]);
$this->assertEquals($expected['degraded'], $pluginResult->isDegraded());
$this->assertSame($expected['taskDescription'], $pluginResult->generateTaskDescription());
$this->assertSame($expected['formattedOutput'], $pluginResult->generateFormattedOutput(10));
$this->assertEquals($expected['degraded'], $pluginResult->isDegraded());
$this->assertEquals($expected['improved'], $pluginResult->isImproved());
$this->assertEquals($expected['unchanged'], $pluginResult->isUnchanged());
}
}
@@ -22,6 +22,19 @@ public function dataProvider()
'taskDescription' => '',
]
],
'unchangedWithFail' => [
[
'test', 1, 1,
],
[
'unchanged' => true,
'improved' => false,
'degraded' => false,
'string' => 'test',
'formattedOutput' => "test | 1\t=> 1\tpls improve me :-(",
'taskDescription' => '',
]
],
'improved' => [
[
'test', 1, 0,
@@ -51,40 +64,6 @@ public function dataProvider()
];
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testIsUnchanged(array $input, array $expected)
{
$sut = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertEquals($expected['unchanged'], $sut->isUnchanged());
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testIsImproved(array $input, array $expected)
{
$sut = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertEquals($expected['improved'], $sut->isImproved());
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testIsDegraded(array $input, array $expected)
{
$sut = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertEquals($expected['degraded'], $sut->isDegraded());
}
/**
* @dataProvider dataProvider
* @param array $input
@@ -96,25 +75,33 @@ public function test__toString(array $input, array $expected)
$this->assertEquals($expected['string'], $sut->__toString());
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testGenerateFormattedOutput(array $input, array $expected)
public function testFormating(array $input, array $expected)
{
$sut = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertSame($expected['formattedOutput'], $sut->generateFormattedOutput(10));
$pluginResult = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertEquals($expected['degraded'], $pluginResult->isDegraded());
$this->assertSame($expected['taskDescription'], $pluginResult->generateTaskDescription());
$this->assertSame($expected['formattedOutput'], $pluginResult->generateFormattedOutput(10));
$this->assertEquals($expected['degraded'], $pluginResult->isDegraded());
$this->assertEquals($expected['improved'], $pluginResult->isImproved());
$this->assertEquals($expected['unchanged'], $pluginResult->isUnchanged());
}
/**
* @dataProvider dataProvider
* @param array $input
* @param array $expected
*/
public function testGenerateTaskDescription(array $input, array $expected)
public function testSetterGetter()
{
$sut = new BitbucketNotifyPluginResult($input[0], $input[1], $input[2]);
$this->assertSame($expected['taskDescription'], $sut->generateTaskDescription());
$pluginResult = new BitbucketNotifyPluginResult('noname', 9, 9);
$this->assertEquals(false, $pluginResult->isDegraded());
$this->assertEquals(false, $pluginResult->isImproved());
$this->assertEquals(true, $pluginResult->isUnchanged());
$pluginResult->setLeft(99);
$pluginResult->setRight(199);
$pluginResult->setPlugin('BestPluginEver4Cod1ng');
$this->assertEquals('99', $pluginResult->getLeft());
$this->assertEquals(199, $pluginResult->getRight());
$this->assertEquals('BestPluginEver4Cod1ng', $pluginResult->getPlugin());
$this->assertEquals(true, $pluginResult->isDegraded());
$this->assertEquals(false, $pluginResult->isImproved());
$this->assertEquals(false, $pluginResult->isUnchanged());
}
}

0 comments on commit eef6f16

Please sign in to comment.
You can’t perform that action at this time.