Skip to content

Commit

Permalink
Merge pull request #17 from Ali-Shaikh/v2
Browse files Browse the repository at this point in the history
[v2] Added support for PHP 8
  • Loading branch information
mtownsend5512 authored Jan 11, 2021
2 parents ecf7bf7 + f19d651 commit b43f178
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 47 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ A PHP package to show users how long it takes to read content.

Install via composer:


```
composer require mtownsend/read-time
```


*This package is designed to work with any PHP 7.0+ application but has special support for Laravel.*

### Registering the service provider (Laravel)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
]
},
"require": {
"php": "~7.0"
"php": "^7.4|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
"phpunit/phpunit": "^9.3"
},
"autoload-dev": {
"psr-4": {
Expand Down
26 changes: 10 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="MyPackage Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
58 changes: 29 additions & 29 deletions tests/ReadTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ReadTimeTest extends TestCase
/** @test string */
protected $sidebarContent;

protected function setUp()
protected function setUp(): void
{
$this->mainContent = <<<HTML
$this->mainContent = <<<HTML
<h2>Chicken Enchiladas</h2>
<small>By Leroy Jenkins</small>
<p>
Expand All @@ -42,7 +42,7 @@ protected function setUp()
</li>
</ol>
HTML;
$this->sidebarContent = <<<HTML
$this->sidebarContent = <<<HTML
<ul>
<li>
<p>
Expand Down Expand Up @@ -75,99 +75,99 @@ protected function setUp()
/** @test */
public function can_output_read_time()
{
$result = (new ReadTime($this->mainContent))->get();
$result = (new ReadTime($this->mainContent))->get();
$this->assertSame($result, '1 minute read');
}

/** @test */
public function can_accept_array_of_content()
{
$result = (new ReadTime([$this->mainContent, $this->sidebarContent]))->get();
$result = (new ReadTime([$this->mainContent, $this->sidebarContent]))->get();
$this->assertSame($result, '1 minute read');
}

/** @test */
public function can_change_wpm()
{
$result = (new ReadTime($this->mainContent))->wpm(150)->toArray();
$result = (new ReadTime($this->mainContent))->wpm(150)->toArray();
$this->assertSame($result['words_per_minute'], 150);
}

/** @test */
public function can_set_time_only()
{
$result = (new ReadTime($this->mainContent))->timeOnly(true)->toArray();
$result = (new ReadTime($this->mainContent))->timeOnly(true)->toArray();
$this->assertTrue($result['time_only']);
}

/** @test */
public function can_allow_seconds()
{
$result = (new ReadTime($this->mainContent))->omitSeconds(false)->toArray();
$result = (new ReadTime($this->mainContent))->omitSeconds(false)->toArray();
$this->assertFalse($result['omit_seconds']);
}

/** @test */
public function can_change_translation()
{
$spanish = [
'min' => 'min',
'minute' => 'minuto',
'sec' => 'seg',
'second' => 'segundo',
'read' => 'leer'
];
$result = (new ReadTime($this->mainContent))->setTranslation($spanish)->getTranslation('read');
$spanish = [
'min' => 'min',
'minute' => 'minuto',
'sec' => 'seg',
'second' => 'segundo',
'read' => 'leer'
];
$result = (new ReadTime($this->mainContent))->setTranslation($spanish)->getTranslation('read');
$this->assertSame($result, 'leer');
}

/** @test */
public function can_get_translation_array()
{
$result = (new ReadTime($this->mainContent))->getTranslation();
$this->assertInternalType('array', $result);
$result = (new ReadTime($this->mainContent))->getTranslation();
$this->assertIsArray($result);
}

/** @test */
public function can_get_translation_key()
{
$result = (new ReadTime($this->mainContent))->getTranslation('minute');
$this->assertSame($result, 'minute');
$result = (new ReadTime($this->mainContent))->getTranslation('minute');
$this->assertSame($result, 'minute');
}

/** @test */
public function can_read_right_to_left()
{
$result = (new ReadTime($this->mainContent))->omitSeconds(false)->rtl()->get();
$result = (new ReadTime($this->mainContent))->omitSeconds(false)->rtl()->get();
$this->assertSame($result, 'read second 10 minute 1');
}

/** @test */
public function can_output_array()
{
$result = (new ReadTime($this->mainContent))->toArray();
$this->assertInternalType('array', $result);
$result = (new ReadTime($this->mainContent))->toArray();
$this->assertIsArray($result);
}

/** @test */
public function can_output_json()
{
$result = (new ReadTime($this->mainContent))->toJson();
$this->assertInternalType('string', $result);
$result = (new ReadTime($this->mainContent))->toJson();
$this->assertJson($result);
}

/** @test */
public function can_invoke_class_for_read_time()
{
$result = new ReadTime($this->mainContent);
$this->assertInternalType('string', $result());
$result = new ReadTime($this->mainContent);
$this->assertIsString($result());
}

/** @test */
public function can_cast_as_string_for_read_time()
{
$result = new ReadTime($this->mainContent);
$this->assertInternalType('string', (string) $result);
$result = new ReadTime($this->mainContent);
$this->assertIsString((string)$result);
}

/** @test */
Expand Down

0 comments on commit b43f178

Please sign in to comment.