Skip to content

Commit b698a05

Browse files
authored
Bump minimum version of PHPUnit to v10.5 and support v11 (#6)
1 parent 725333c commit b698a05

File tree

5 files changed

+87
-93
lines changed

5 files changed

+87
-93
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"symfony/options-resolver": "^6.1 || ^7.0"
1212
},
1313
"require-dev": {
14-
"phpunit/phpunit": "^9.6",
14+
"phpunit/phpunit": "^10.5 || ^11.0",
1515
"realodix/relax": "^1.7"
1616
},
1717
"minimum-stability": "dev",

phpunit.xml.dist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
55
bootstrap="vendor/autoload.php"
6-
cacheResultFile=".tmp/PHPUnit/.phpunit.result.cache"
6+
cacheDirectory=".tmp/PHPUnit"
7+
cacheResult="true"
78
colors="true"
89
>
910
<testsuites>
1011
<testsuite name="default">
1112
<directory>tests</directory>
1213
</testsuite>
1314
</testsuites>
14-
15-
<coverage cacheDirectory=".tmp/PHPUnit">
15+
<source>
1616
<include>
1717
<directory>src</directory>
1818
</include>
19-
</coverage>
19+
</source>
2020
</phpunit>

tests/MediumTest.php renamed to tests/Articles/MediumTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ class MediumTest extends TestCase
1313
* Reference
1414
* - https://medium.com/@dahul/inside-medium-94931f66eebd
1515
* - https://blog.medium.com/read-time-and-you-bc2048ab620c
16-
*
17-
* @test
1816
*/
19-
public function articleWithManyImages()
17+
public function testArticlesThatContainManyImages()
2018
{
2119
$wpm = 265;
2220

@@ -40,10 +38,8 @@ public function articleWithManyImages()
4038
* Reference
4139
* - https://medium.com/@fchimero/this-should-only-take-a-minute-or-four-probably-e38bb7bf2adf
4240
* - https://blog.medium.com/read-time-and-you-bc2048ab620c
43-
*
44-
* @test
4541
*/
46-
public function complexityOfAnArticle()
42+
public function testComplexArticle()
4743
{
4844
$wpm = 265;
4945

tests/ConfigurationTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Realodix\ReadTime\Test;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Realodix\ReadTime\ReadTime;
7+
8+
class ConfigurationTest extends TestCase
9+
{
10+
/**
11+
* Words Per Minut must be able to be changed as needed, and must be in accordance
12+
* with the language. Param 1 must be for counting latin script, param 2 must be for
13+
* counting Chinese/Japanese/Korean script.
14+
*/
15+
#[Test]
16+
public function readingSpeedMustAdjustToTheLanguage()
17+
{
18+
$wpm = 1;
19+
$content = str_repeat('a ', $wpm);
20+
$actual = (new ReadTime($content, $wpm))->toArray();
21+
$this->assertSame($wpm, $actual['word_time']);
22+
23+
$content = str_repeat('陳る김', $wpm);
24+
$actual = (new ReadTime($content, $wpm, 12, 3))->toArray();
25+
$this->assertSame(1, $actual['word_time_cjk']);
26+
}
27+
28+
/**
29+
* Translation must be able to be changed as needed
30+
*/
31+
#[Test]
32+
public function setTranslation()
33+
{
34+
$customTranslation = 'foo';
35+
$actual = (new ReadTime('word'))
36+
->setTranslation(['less_than' => $customTranslation])
37+
->get();
38+
39+
$this->assertSame($customTranslation, $actual);
40+
}
41+
42+
/**
43+
* Set translation with wrong key, and it should return default translation
44+
*/
45+
#[Test]
46+
public function setTranslationWithWrongKey()
47+
{
48+
$this->expectException(\Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException::class);
49+
50+
(new ReadTime('word'))
51+
->setTranslation(['foo' => 'bar'])
52+
->get();
53+
}
54+
55+
/**
56+
* Translation must be in accordance with data type
57+
*/
58+
#[Test]
59+
public function setTranslationWithWrongDataType()
60+
{
61+
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);
62+
63+
(new ReadTime('word'))
64+
->setTranslation(['less_than' => true])
65+
->get();
66+
}
67+
}

tests/ReadTimeTest.php

Lines changed: 12 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
class ReadTimeTest extends TestCase
88
{
9-
/** @test */
10-
public function readTime()
9+
public function testReadTimeMethod()
1110
{
1211
$wpm = 265;
1312

@@ -25,27 +24,7 @@ public function readTime()
2524
);
2625
}
2726

28-
/**
29-
* Words Per Minut must be able to be changed as needed, and must be in accordance
30-
* with the language. Param 1 must be for counting latin script, param 2 must be for
31-
* counting Chinese/Japanese/Korean script.
32-
*
33-
* @test
34-
*/
35-
public function readingSpeedMustAdjustToTheLanguage()
36-
{
37-
$wpm = 1;
38-
$content = str_repeat('a ', $wpm);
39-
$actual = (new ReadTime($content, $wpm))->toArray();
40-
$this->assertSame($wpm, $actual['word_time']);
41-
42-
$content = str_repeat('陳る김', $wpm);
43-
$actual = (new ReadTime($content, $wpm, 12, 3))->toArray();
44-
$this->assertSame(1, $actual['word_time_cjk']);
45-
}
46-
47-
/** @test */
48-
public function canInputArray()
27+
public function testInputArray()
4928
{
5029
$wpm = 265;
5130
$article = str_repeat('word ', $wpm);
@@ -57,8 +36,7 @@ public function canInputArray()
5736
);
5837
}
5938

60-
/** @test */
61-
public function canInputArrayMultiDimensional()
39+
public function testInputMultiDimensionalArray()
6240
{
6341
$wpm = 265;
6442
$article = str_repeat('word ', $wpm);
@@ -70,8 +48,7 @@ public function canInputArrayMultiDimensional()
7048
);
7149
}
7250

73-
/** @test */
74-
public function duration()
51+
public function testOutputDuration()
7552
{
7653
$wpm = 60;
7754

@@ -94,8 +71,7 @@ public function duration()
9471
);
9572
}
9673

97-
/** @test */
98-
public function imageReadTime()
74+
public function testOutputImageTime()
9975
{
10076
$content = str_repeat('<img src="image.jpg">', 5);
10177
$actual = (new ReadTime($content))->toArray();
@@ -113,8 +89,7 @@ public function imageReadTime()
11389
$this->assertSame(81.0, $actual['image_time'] * 60);
11490
}
11591

116-
/** @test */
117-
public function imagesCount()
92+
public function testOutputTotalImages()
11893
{
11994
$content =
12095
'
@@ -127,22 +102,19 @@ public function imagesCount()
127102
$this->assertSame(2, (new ReadTime($content))->toArray()['total_images']);
128103
}
129104

130-
/** @test */
131-
public function canOutputArray()
105+
public function testOutputArrayDataType()
132106
{
133107
$result = (new ReadTime('foo'))->toArray();
134108
$this->assertIsArray($result);
135109
}
136110

137-
/** @test */
138-
public function canOutputJson()
111+
public function testOutputJsonDataType()
139112
{
140113
$result = (new ReadTime('foo'))->toJson();
141114
$this->assertJson($result);
142115
}
143116

144-
/** @test */
145-
public function outputArray()
117+
public function testOutput()
146118
{
147119
$wpm = 265;
148120
$imageTime = 12;
@@ -152,7 +124,9 @@ public function outputArray()
152124
$cjkCharacters = '陳港生' // Jackie Chan
153125
.'るろうに剣心' // Rurouni Kenshin
154126
.'김제니'; // Jennie Kim
155-
$actualDuration = ($totalWords / $wpm) + (($imageTime + ($imageTime - 1)) / 60) + (mb_strlen($cjkCharacters) / $cpm);
127+
$actualDuration = ($totalWords / $wpm)
128+
+ (($imageTime + ($imageTime - 1)) / 60)
129+
+ (mb_strlen($cjkCharacters) / $cpm);
156130

157131
$content = str_repeat('<img src="image.jpg">', $t_img)
158132
.str_repeat('word ', $totalWords)
@@ -173,47 +147,4 @@ public function outputArray()
173147

174148
$this->assertSame($expected, $actual);
175149
}
176-
177-
/**
178-
* Translation must be able to be changed as needed
179-
*
180-
* @test
181-
*/
182-
public function setTranslation()
183-
{
184-
$customTranslation = 'foo';
185-
$actual = (new ReadTime('word'))
186-
->setTranslation(['less_than' => $customTranslation])
187-
->get();
188-
189-
$this->assertSame($customTranslation, $actual);
190-
}
191-
192-
/**
193-
* Set translation with wrong key, and it should return default translation
194-
*
195-
* @test
196-
*/
197-
public function setTranslationWithWrongKey()
198-
{
199-
$this->expectException(\Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException::class);
200-
201-
(new ReadTime('word'))
202-
->setTranslation(['foo' => 'bar'])
203-
->get();
204-
}
205-
206-
/**
207-
* Translation must be in accordance with data type
208-
*
209-
* @test
210-
*/
211-
public function setTranslationWithWrongDataType()
212-
{
213-
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);
214-
215-
(new ReadTime('word'))
216-
->setTranslation(['less_than' => true])
217-
->get();
218-
}
219150
}

0 commit comments

Comments
 (0)