Skip to content

Commit

Permalink
Bump minimum version of PHPUnit to v10.5 and support v11 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix authored Mar 28, 2024
1 parent 725333c commit b698a05
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 93 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"symfony/options-resolver": "^6.1 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.5 || ^11.0",
"realodix/relax": "^1.7"
},
"minimum-stability": "dev",
Expand Down
10 changes: 5 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".tmp/PHPUnit/.phpunit.result.cache"
cacheDirectory=".tmp/PHPUnit"
cacheResult="true"
colors="true"
>
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".tmp/PHPUnit">
<source>
<include>
<directory>src</directory>
</include>
</coverage>
</source>
</phpunit>
8 changes: 2 additions & 6 deletions tests/MediumTest.php → tests/Articles/MediumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ class MediumTest extends TestCase
* Reference
* - https://medium.com/@dahul/inside-medium-94931f66eebd
* - https://blog.medium.com/read-time-and-you-bc2048ab620c
*
* @test
*/
public function articleWithManyImages()
public function testArticlesThatContainManyImages()
{
$wpm = 265;

Expand All @@ -40,10 +38,8 @@ public function articleWithManyImages()
* Reference
* - https://medium.com/@fchimero/this-should-only-take-a-minute-or-four-probably-e38bb7bf2adf
* - https://blog.medium.com/read-time-and-you-bc2048ab620c
*
* @test
*/
public function complexityOfAnArticle()
public function testComplexArticle()
{
$wpm = 265;

Expand Down
67 changes: 67 additions & 0 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Realodix\ReadTime\Test;

use PHPUnit\Framework\Attributes\Test;
use Realodix\ReadTime\ReadTime;

class ConfigurationTest extends TestCase
{
/**
* Words Per Minut must be able to be changed as needed, and must be in accordance
* with the language. Param 1 must be for counting latin script, param 2 must be for
* counting Chinese/Japanese/Korean script.
*/
#[Test]
public function readingSpeedMustAdjustToTheLanguage()
{
$wpm = 1;
$content = str_repeat('a ', $wpm);
$actual = (new ReadTime($content, $wpm))->toArray();
$this->assertSame($wpm, $actual['word_time']);

$content = str_repeat('陳る김', $wpm);
$actual = (new ReadTime($content, $wpm, 12, 3))->toArray();
$this->assertSame(1, $actual['word_time_cjk']);
}

/**
* Translation must be able to be changed as needed
*/
#[Test]
public function setTranslation()
{
$customTranslation = 'foo';
$actual = (new ReadTime('word'))
->setTranslation(['less_than' => $customTranslation])
->get();

$this->assertSame($customTranslation, $actual);
}

/**
* Set translation with wrong key, and it should return default translation
*/
#[Test]
public function setTranslationWithWrongKey()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException::class);

(new ReadTime('word'))
->setTranslation(['foo' => 'bar'])
->get();
}

/**
* Translation must be in accordance with data type
*/
#[Test]
public function setTranslationWithWrongDataType()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);

(new ReadTime('word'))
->setTranslation(['less_than' => true])
->get();
}
}
93 changes: 12 additions & 81 deletions tests/ReadTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

class ReadTimeTest extends TestCase
{
/** @test */
public function readTime()
public function testReadTimeMethod()
{
$wpm = 265;

Expand All @@ -25,27 +24,7 @@ public function readTime()
);
}

/**
* Words Per Minut must be able to be changed as needed, and must be in accordance
* with the language. Param 1 must be for counting latin script, param 2 must be for
* counting Chinese/Japanese/Korean script.
*
* @test
*/
public function readingSpeedMustAdjustToTheLanguage()
{
$wpm = 1;
$content = str_repeat('a ', $wpm);
$actual = (new ReadTime($content, $wpm))->toArray();
$this->assertSame($wpm, $actual['word_time']);

$content = str_repeat('陳る김', $wpm);
$actual = (new ReadTime($content, $wpm, 12, 3))->toArray();
$this->assertSame(1, $actual['word_time_cjk']);
}

/** @test */
public function canInputArray()
public function testInputArray()
{
$wpm = 265;
$article = str_repeat('word ', $wpm);
Expand All @@ -57,8 +36,7 @@ public function canInputArray()
);
}

/** @test */
public function canInputArrayMultiDimensional()
public function testInputMultiDimensionalArray()
{
$wpm = 265;
$article = str_repeat('word ', $wpm);
Expand All @@ -70,8 +48,7 @@ public function canInputArrayMultiDimensional()
);
}

/** @test */
public function duration()
public function testOutputDuration()
{
$wpm = 60;

Expand All @@ -94,8 +71,7 @@ public function duration()
);
}

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

/** @test */
public function imagesCount()
public function testOutputTotalImages()
{
$content =
'
Expand All @@ -127,22 +102,19 @@ public function imagesCount()
$this->assertSame(2, (new ReadTime($content))->toArray()['total_images']);
}

/** @test */
public function canOutputArray()
public function testOutputArrayDataType()
{
$result = (new ReadTime('foo'))->toArray();
$this->assertIsArray($result);
}

/** @test */
public function canOutputJson()
public function testOutputJsonDataType()
{
$result = (new ReadTime('foo'))->toJson();
$this->assertJson($result);
}

/** @test */
public function outputArray()
public function testOutput()
{
$wpm = 265;
$imageTime = 12;
Expand All @@ -152,7 +124,9 @@ public function outputArray()
$cjkCharacters = '陳港生' // Jackie Chan
.'るろうに剣心' // Rurouni Kenshin
.'김제니'; // Jennie Kim
$actualDuration = ($totalWords / $wpm) + (($imageTime + ($imageTime - 1)) / 60) + (mb_strlen($cjkCharacters) / $cpm);
$actualDuration = ($totalWords / $wpm)
+ (($imageTime + ($imageTime - 1)) / 60)
+ (mb_strlen($cjkCharacters) / $cpm);

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

$this->assertSame($expected, $actual);
}

/**
* Translation must be able to be changed as needed
*
* @test
*/
public function setTranslation()
{
$customTranslation = 'foo';
$actual = (new ReadTime('word'))
->setTranslation(['less_than' => $customTranslation])
->get();

$this->assertSame($customTranslation, $actual);
}

/**
* Set translation with wrong key, and it should return default translation
*
* @test
*/
public function setTranslationWithWrongKey()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException::class);

(new ReadTime('word'))
->setTranslation(['foo' => 'bar'])
->get();
}

/**
* Translation must be in accordance with data type
*
* @test
*/
public function setTranslationWithWrongDataType()
{
$this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class);

(new ReadTime('word'))
->setTranslation(['less_than' => true])
->get();
}
}

0 comments on commit b698a05

Please sign in to comment.