Skip to content

Commit f030d5b

Browse files
committed
Added tests for getters/setters to increase coverage.
Refactored assertions to use static invocation.
1 parent 5310f34 commit f030d5b

File tree

5 files changed

+75
-33
lines changed

5 files changed

+75
-33
lines changed

test/Integration/Byte/ByteFormatterTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace ScriptFUSIONTest\Integration;
2+
namespace ScriptFUSIONTest\Integration\Byte;
33

44
use ScriptFUSION\Byte\Base;
55
use ScriptFUSION\Byte\ByteFormatter;
@@ -19,7 +19,7 @@ protected function setUp()
1919
/** @dataProvider provideBinaryIntegers */
2020
public function testBinaryFormat($integer, $formatted)
2121
{
22-
$this->assertSame($formatted, $this->formatter->setBase(Base::BINARY)->format($integer));
22+
self::assertSame($formatted, $this->formatter->setBase(Base::BINARY)->format($integer));
2323
}
2424

2525
public function provideBinaryIntegers()
@@ -50,7 +50,7 @@ public function provideBinaryIntegers()
5050
/** @dataProvider provideDecimalIntegers */
5151
public function testDecimalFormat($integer, $formatted)
5252
{
53-
$this->assertSame($formatted, $this->formatter->setBase(Base::DECIMAL)->format($integer));
53+
self::assertSame($formatted, $this->formatter->setBase(Base::DECIMAL)->format($integer));
5454
}
5555

5656
public function provideDecimalIntegers()
@@ -79,8 +79,8 @@ public function provideDecimalIntegers()
7979
/** @dataProvider providePrecisionIntegers */
8080
public function testPrecision($integer, $formatted)
8181
{
82-
$this->assertSame($formatted, $this->formatter->setPrecision(2)->format($integer));
83-
$this->assertSame($formatted, $this->formatter->setPrecision(5)->format($integer, 2));
82+
self::assertSame($formatted, $this->formatter->setPrecision(2)->format($integer));
83+
self::assertSame($formatted, $this->formatter->setPrecision(5)->format($integer, 2));
8484
}
8585

8686
public function providePrecisionIntegers()
@@ -105,7 +105,7 @@ public function providePrecisionIntegers()
105105
/** @dataProvider provideFormats */
106106
public function testFormats($format, $formatted)
107107
{
108-
$this->assertSame($formatted, $this->formatter->setFormat($format)->format($this->formatter->getBase()));
108+
self::assertSame($formatted, $this->formatter->setFormat($format)->format($this->formatter->getBase()));
109109
}
110110

111111
public function provideFormats()
@@ -127,7 +127,7 @@ public function testFixedExponent($exponent, $bytes, $formatted)
127127
$this->formatter->setPrecision(8);
128128

129129
$this->formatter->setFixedExponent($exponent);
130-
$this->assertSame($formatted, $this->formatter->format($bytes));
130+
self::assertSame($formatted, $this->formatter->format($bytes));
131131
}
132132

133133
public function provideFixedExponents()
@@ -161,7 +161,7 @@ public function testDisableAutomaticPrecision()
161161
{
162162
$this->formatter->disableAutomaticPrecision();
163163

164-
$this->assertSame('512.50K', $this->formatter->format(0x80200, 2));
164+
self::assertSame('512.50K', $this->formatter->format(0x80200, 2));
165165
}
166166

167167
public function testCustomUnitSequence()
@@ -173,6 +173,6 @@ public function testCustomUnitSequence()
173173
->getMock()
174174
);
175175

176-
$this->assertSame('1 foo', $formatter->format(1));
176+
self::assertSame('1 foo', $formatter->format(1));
177177
}
178178
}

test/Integration/DocumentationTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,58 @@ final class DocumentationTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public function testBasicUsage()
1212
{
13-
$this->assertSame('512 KiB', (new ByteFormatter)->format(0x80000));
13+
self::assertSame('512 KiB', (new ByteFormatter)->format(0x80000));
1414

15-
$this->assertSame('500 KB', (new ByteFormatter)->setBase(Base::DECIMAL)->format(500000));
15+
self::assertSame('500 KB', (new ByteFormatter)->setBase(Base::DECIMAL)->format(500000));
1616
}
1717

1818
public function testPrecision()
1919
{
20-
$this->assertSame('513 KiB', (new ByteFormatter)->format(0x80233));
20+
self::assertSame('513 KiB', (new ByteFormatter)->format(0x80233));
2121

22-
$this->assertSame('512.55 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80233));
22+
self::assertSame('512.55 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80233));
2323

24-
$this->assertSame('512.5 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80200));
24+
self::assertSame('512.5 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80200));
2525

26-
$this->assertSame(
26+
self::assertSame(
2727
'512.50 KiB',
2828
(new ByteFormatter)->setPrecision(2)->disableAutomaticPrecision()->format(0x80200)
2929
);
3030

31-
$this->assertSame('512.5498 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80233, 4));
31+
self::assertSame('512.5498 KiB', (new ByteFormatter)->setPrecision(2)->format(0x80233, 4));
3232
}
3333

3434
public function testOutputFormat()
3535
{
36-
$this->assertSame('512KiB', (new ByteFormatter)->setFormat('%v%u')->format(0x80000));
36+
self::assertSame('512KiB', (new ByteFormatter)->setFormat('%v%u')->format(0x80000));
3737
}
3838

3939
public function testFixedExponent()
4040
{
41-
$this->assertSame('1024 KiB', (new ByteFormatter)->setFixedExponent(1)->format(1024 * 1024));
41+
self::assertSame('1024 KiB', (new ByteFormatter)->setFixedExponent(1)->format(1024 * 1024));
4242
}
4343

4444
public function testSymbolDecorator()
4545
{
46-
$this->assertSame(
46+
self::assertSame(
4747
'512 KB',
4848
(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_METRIC)))
4949
->format(0x80000)
5050
);
5151

52-
$this->assertSame(
52+
self::assertSame(
5353
'512 K',
5454
(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE)))
5555
->format(0x80000)
5656
);
5757

58-
$this->assertSame(
58+
self::assertSame(
5959
'512',
6060
(new ByteFormatter(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE)))
6161
->format(512)
6262
);
6363

64-
$this->assertSame(
64+
self::assertSame(
6565
'512 B',
6666
(new ByteFormatter(
6767
(new SymbolDecorator(SymbolDecorator::SUFFIX_NONE))
@@ -73,13 +73,13 @@ public function testSymbolDecorator()
7373

7474
public function testNameDecorator()
7575
{
76-
$this->assertSame(
76+
self::assertSame(
7777
'512 kibibytes',
7878
(new ByteFormatter(new NameDecorator))
7979
->format(0x80000)
8080
);
8181

82-
$this->assertSame(
82+
self::assertSame(
8383
'500 kilobytes',
8484
(new ByteFormatter(new NameDecorator))
8585
->setBase(Base::DECIMAL)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace ScriptFUSIONTest\Unit\Byte;
3+
4+
use ScriptFUSION\Byte\ByteFormatter;
5+
6+
final class ByteFormatterTest extends \PHPUnit_Framework_TestCase
7+
{
8+
/**
9+
* @var ByteFormatter
10+
*/
11+
private $formatter;
12+
13+
protected function setUp()
14+
{
15+
$this->formatter = new ByteFormatter;
16+
}
17+
18+
public function testFormat()
19+
{
20+
self::assertSame($format = 'foo', $this->formatter->setFormat($format)->getFormat());
21+
}
22+
23+
public function testAutomaticPrecision()
24+
{
25+
self::assertTrue($this->formatter->hasAutomaticPrecision());
26+
self::assertFalse($this->formatter->disableAutomaticPrecision()->hasAutomaticPrecision());
27+
self::assertTrue($this->formatter->enableAutomaticPrecision()->hasAutomaticPrecision());
28+
}
29+
30+
public function testFixedExponent()
31+
{
32+
self::assertFalse($this->formatter->hasFixedExponent());
33+
self::assertSame($exponent = 2, $this->formatter->setFixedExponent($exponent)->getFixedExponent());
34+
self::assertTrue($this->formatter->hasFixedExponent());
35+
self::assertFalse($this->formatter->clearFixedExponent()->hasFixedExponent());
36+
}
37+
}

test/Unit/Byte/Unit/NameDecoratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testBinarySequence()
2323
'yobibytes',
2424
] as $exponent => $name
2525
) {
26-
$this->assertSame($name, $decorator->decorate($exponent, Base::BINARY, 0));
26+
self::assertSame($name, $decorator->decorate($exponent, Base::BINARY, 0));
2727
}
2828
}
2929

@@ -44,7 +44,7 @@ public function testDecimalSequence()
4444
'yottabytes',
4545
] as $exponent => $name
4646
) {
47-
$this->assertSame($name, $decorator->decorate($exponent, Base::DECIMAL, 0));
47+
self::assertSame($name, $decorator->decorate($exponent, Base::DECIMAL, 0));
4848
}
4949
}
5050

@@ -65,7 +65,7 @@ public function testSingular()
6565
'yobibyte',
6666
] as $exponent => $name
6767
) {
68-
$this->assertSame($name, $decorator->decorate($exponent, Base::BINARY, 1));
68+
self::assertSame($name, $decorator->decorate($exponent, Base::BINARY, 1));
6969
}
7070
}
7171
}

test/Unit/Byte/Unit/SymbolDecoratorTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function testNoSuffix()
1111
$decorator = new SymbolDecorator(SymbolDecorator::SUFFIX_NONE);
1212

1313
foreach (['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] as $exponent => $symbol) {
14-
$this->assertSame($symbol, $decorator->decorate($exponent, 0, 0));
14+
self::assertSame($symbol, $decorator->decorate($exponent, 0, 0));
1515
}
1616
}
1717

@@ -20,7 +20,7 @@ public function testAlwaysShowUnit()
2020
$decorator = (new SymbolDecorator(SymbolDecorator::SUFFIX_NONE))->alwaysShowUnit();
2121

2222
foreach (['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] as $exponent => $symbol) {
23-
$this->assertSame($symbol, $decorator->decorate($exponent, 0, 0));
23+
self::assertSame($symbol, $decorator->decorate($exponent, 0, 0));
2424
}
2525
}
2626

@@ -29,7 +29,7 @@ public function testMetricSuffix()
2929
$decorator = new SymbolDecorator(SymbolDecorator::SUFFIX_METRIC);
3030

3131
foreach (['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] as $exponent => $symbol) {
32-
$this->assertSame($symbol, $decorator->decorate($exponent, 0, 0));
32+
self::assertSame($symbol, $decorator->decorate($exponent, 0, 0));
3333
}
3434
}
3535

@@ -38,15 +38,20 @@ public function testIecSuffix()
3838
$decorator = new SymbolDecorator(SymbolDecorator::SUFFIX_IEC);
3939

4040
foreach (['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] as $exponent => $symbol) {
41-
$this->assertSame($symbol, $decorator->decorate($exponent, 0, 0));
41+
self::assertSame($symbol, $decorator->decorate($exponent, 0, 0));
4242
}
4343
}
4444

4545
public function testAutomaticUnitSwitching()
4646
{
4747
$decorator = new SymbolDecorator;
4848

49-
$this->assertSame('KiB', $decorator->decorate(1, Base::BINARY, 0));
50-
$this->assertSame('KB', $decorator->decorate(1, Base::DECIMAL, 0));
49+
self::assertSame('KiB', $decorator->decorate(1, Base::BINARY, 0));
50+
self::assertSame('KB', $decorator->decorate(1, Base::DECIMAL, 0));
51+
}
52+
53+
public function testSuffix()
54+
{
55+
self::assertSame($suffix = 'foo', (new SymbolDecorator)->setSuffix($suffix)->getSuffix());
5156
}
5257
}

0 commit comments

Comments
 (0)