Skip to content

Commit c01ebbd

Browse files
authored
Leave the test suite with nothing to report, and keep it that way (#920)
Three things the suite has been printing under every run, none of them noise. `getimagesize()` answers `false` for a file it cannot measure -- an SVG, a video -- and both callers destructured that answer straight into a width and a height: `Cannot use bool as array`, three tests, twice each. The size such a file ends up with is the size it already had, which is nothing, so the fix is to assign only when there is something to assign. `HashTable::add()` looked the source up by `getHashIndex()`, which is null until the table has given the object one. `isset($array[null])` reads the key as an empty string, so the lookup was correct and merely deprecated -- 184 tests said so on every run. It now asks whether there is an index first. The five mock objects nobody configured an expectation on are stubs, which is what PHPUnit says in the notice, so they are built with `createStub()`. The gates that hold this are split in two, because PHPUnit splits them. `phpunit.xml.dist` takes the three the declared 9.3 schema knows -- `failOnWarning`, `failOnRisky`, `failOnEmptyTestSuite` -- and the rest exist only on the command line, so the workflow passes `--fail-on-deprecation`, `--fail-on-notice` and `--fail-on-phpunit-deprecation` on one leg. Without them PHPUnit ends a run that had something to report with "OK, but there were issues" and exit code 0, and CI stays green while the report grows back. That leg is 8.5: the newest PHP is where a deprecation appears first. It also takes the coverage run over from 8.3, so that exactly one leg of the matrix is out of the ordinary rather than two.
1 parent d4f5ca9 commit c01ebbd

12 files changed

Lines changed: 63 additions & 23 deletions

File tree

.github/workflows/php.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,26 @@ jobs:
7575
with:
7676
php-version: ${{ matrix.php }}
7777
extensions: gd, xml, zip
78-
coverage: ${{ (matrix.php == '8.3') && 'xdebug' || 'none' }}
78+
coverage: ${{ (matrix.php == '8.5') && 'xdebug' || 'none' }}
7979

8080
- uses: actions/checkout@v2
8181

8282
- name: Composer Install
8383
run: composer install --ansi --prefer-dist --no-interaction --no-progress
8484

8585
- name: Run phpunit
86-
if: matrix.php != '8.3'
86+
if: matrix.php != '8.5'
8787
run: ./vendor/bin/phpunit -c phpunit.xml.dist --no-coverage
8888

89+
# the newest PHP is where a new deprecation shows up first, so that leg is the one
90+
# that refuses to be green while the suite still has something to report -- and the
91+
# one that gathers the coverage, so that there is a single leg out of the ordinary
8992
- name: Run phpunit
90-
if: matrix.php == '8.3'
91-
run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/clover.xml
93+
if: matrix.php == '8.5'
94+
run: ./vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover build/clover.xml --fail-on-deprecation --fail-on-notice --fail-on-phpunit-deprecation
9295

9396
- name: Upload coverage results to Coveralls
94-
if: matrix.php == '8.3'
97+
if: matrix.php == '8.5'
9598
env:
9699
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97100
run: |

docs/changes/1.3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- A master slide is no longer born with a white background nobody asked for by [@dkulyk](http://github.com/dkulyk) in [#909](https://github.com/PHPOffice/PHPPresentation/pull/909)
2222
- ODPresentation Writer : Fixed the background of a master slide being dropped on save by [@dkulyk](http://github.com/dkulyk) in [#912](https://github.com/PHPOffice/PHPPresentation/pull/912)
2323
- PowerPoint2007 Reader : Fixed a shape that asked for no fill being read as having no fill at all, which crashes the ODPresentation Writer on save, by [@dkulyk](http://github.com/dkulyk) in [#915](https://github.com/PHPOffice/PHPPresentation/pull/915)
24+
- Fixed a file with no measurable size (an SVG, a video) warning on `setPath()`, and a fresh object being looked up in the hash table under a null key, by [@dkulyk](http://github.com/dkulyk) in [#920](https://github.com/PHPOffice/PHPPresentation/pull/920)
2425

2526
## BC Breaks
2627
- `\PhpOffice\PhpPresentation\Slide\SlideMaster` is constructed without a background. A deck that relied on the white fill it used to write sets one with `setBackground()`, as [the documentation](https://github.com/PHPOffice/PHPPresentation/blob/develop/docs/usage/slides/introduction.md) shows.

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
colors="true"
77
processIsolation="false"
88
stopOnFailure="false"
9+
failOnWarning="true"
10+
failOnRisky="true"
11+
failOnEmptyTestSuite="true"
912
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
1013
<source>
1114
<include>

src/PhpPresentation/HashTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function add(ComparableInterface $pSource): void
7171
// Determine hashcode
7272
$hashIndex = $pSource->getHashIndex();
7373
$hashCode = $pSource->getHashCode();
74-
if (isset($this->keyMap[$hashIndex])) {
74+
if (null !== $hashIndex && isset($this->keyMap[$hashIndex])) {
7575
$hashCode = $this->keyMap[$hashIndex];
7676
}
7777

src/PhpPresentation/Shape/Drawing/File.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true): self
5555

5656
if ($pVerifyFile) {
5757
if (0 == $this->width && 0 == $this->height) {
58-
[$this->width, $this->height] = getimagesize($this->getPath());
58+
// Not every file a shape can carry is one `getimagesize()` can measure -- an SVG
59+
// and a video both come back as `false`, and a size of nothing is what they had
60+
// before this asked.
61+
$imageSize = getimagesize($this->getPath());
62+
if (is_array($imageSize)) {
63+
[$this->width, $this->height] = $imageSize;
64+
}
5965
}
6066
}
6167

src/PhpPresentation/Slide/Background/Image.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ public function setPath(string $pValue = '', bool $pVerifyFile = true)
7676
}
7777

7878
if (0 == $this->width && 0 == $this->height) {
79-
// Get width/height
80-
[$this->width, $this->height] = getimagesize($pValue);
79+
// Get width/height, when the file is one that has them
80+
$imageSize = getimagesize($pValue);
81+
if (is_array($imageSize)) {
82+
[$this->width, $this->height] = $imageSize;
83+
}
8184
}
8285
}
8386
$this->path = $pValue;

tests/PhpPresentation/Tests/Shape/AutoShapeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use PhpOffice\PhpPresentation\Shape\AutoShape;
2424
use PhpOffice\PhpPresentation\Style\Outline;
25-
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\MockObject\Stub;
2626
use PHPUnit\Framework\TestCase;
2727

2828
class AutoShapeTest extends TestCase
@@ -39,8 +39,8 @@ public function testConstruct(): void
3939

4040
public function testOutline(): void
4141
{
42-
/** @var MockObject&Outline $mock */
43-
$mock = $this->getMockBuilder(Outline::class)->getMock();
42+
/** @var Outline&Stub $mock */
43+
$mock = self::createStub(Outline::class);
4444

4545
$object = new AutoShape();
4646
self::assertInstanceOf(Outline::class, $object->getOutline());

tests/PhpPresentation/Tests/Shape/Chart/AxisTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
2525
use PhpOffice\PhpPresentation\Style\Font;
2626
use PhpOffice\PhpPresentation\Style\Outline;
27-
use PHPUnit\Framework\MockObject\MockObject;
27+
use PHPUnit\Framework\MockObject\Stub;
2828
use PHPUnit\Framework\TestCase;
2929

3030
/**
@@ -105,8 +105,8 @@ public function testGridLines(): void
105105
{
106106
$object = new Axis();
107107

108-
/** @var Gridlines&MockObject $oMock */
109-
$oMock = $this->getMockBuilder(Gridlines::class)->getMock();
108+
/** @var Gridlines&Stub $oMock */
109+
$oMock = self::createStub(Gridlines::class);
110110

111111
self::assertInstanceOf(Axis::class, $object->setMajorGridlines($oMock));
112112
self::assertInstanceOf(Gridlines::class, $object->getMajorGridlines());
@@ -149,8 +149,8 @@ public function testLabelRotation(): void
149149

150150
public function testOutline(): void
151151
{
152-
/** @var MockObject&Outline $oMock */
153-
$oMock = $this->getMockBuilder(Outline::class)->getMock();
152+
/** @var Outline&Stub $oMock */
153+
$oMock = self::createStub(Outline::class);
154154

155155
$object = new Axis();
156156
self::assertInstanceOf(Outline::class, $object->getOutline());

tests/PhpPresentation/Tests/Shape/Chart/GridlinesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use PhpOffice\PhpPresentation\Shape\Chart\Gridlines;
2424
use PhpOffice\PhpPresentation\Style\Outline;
25-
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\MockObject\Stub;
2626
use PHPUnit\Framework\TestCase;
2727

2828
class GridlinesTest extends TestCase
@@ -38,8 +38,8 @@ public function testGetSetOutline(): void
3838
{
3939
$object = new Gridlines();
4040

41-
/** @var MockObject&Outline $oStub */
42-
$oStub = $this->getMockBuilder(Outline::class)->getMock();
41+
/** @var Outline&Stub $oStub */
42+
$oStub = self::createStub(Outline::class);
4343

4444
self::assertInstanceOf(Outline::class, $object->getOutline());
4545
self::assertInstanceOf('PhpOffice\PhpPresentation\Shape\Chart\Gridlines', $object->setOutline($oStub));

tests/PhpPresentation/Tests/Shape/CommentTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use PhpOffice\PhpPresentation\Shape\Comment;
2424
use PhpOffice\PhpPresentation\Shape\Comment\Author;
25-
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\MockObject\Stub;
2626
use PHPUnit\Framework\TestCase;
2727

2828
/**
@@ -47,8 +47,8 @@ public function testGetSetAuthor(): void
4747
{
4848
$object = new Comment();
4949

50-
/** @var Author&MockObject $oStub */
51-
$oStub = $this->getMockBuilder(Author::class)->getMock();
50+
/** @var Author&Stub $oStub */
51+
$oStub = self::createStub(Author::class);
5252

5353
self::assertNull($object->getAuthor());
5454
self::assertInstanceOf(Comment::class, $object->setAuthor($oStub));

0 commit comments

Comments
 (0)