Skip to content

Commit cda54a0

Browse files
committed
add tests
1 parent b478c22 commit cda54a0

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: build
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
run:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
matrix:
10+
operating-system: [ubuntu-latest]
11+
php-versions: ['7.2', '7.3', '7.4', '8.0']
12+
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: ${{ matrix.php-versions }}
22+
extensions: mbstring, intl
23+
coverage: none
24+
25+
- name: Check PHP Version
26+
run: php -v
27+
28+
- name: Check Composer Version
29+
run: composer -V
30+
31+
- name: Check PHP Extensions
32+
run: php -m
33+
34+
- name: Validate composer.json and composer.lock
35+
run: composer validate
36+
37+
- name: Install dependencies
38+
run: composer install --prefer-dist --no-progress --no-suggest
39+
40+
- name: Run test suite
41+
run: vendor/bin/phpunit

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"php": ">=7.2",
2121
"laravel/framework": ">=6.0"
2222
},
23+
"require-dev": {
24+
"orchestra/testbench": ">=5.0"
25+
},
2326
"autoload": {
2427
"psr-4": {
2528
"Pharaonic\\Laravel\\Readable\\": "src"
@@ -28,6 +31,11 @@
2831
"src/Helpers.php"
2932
]
3033
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"Pharaonic\\Laravel\\Readable\\Tests\\": "tests"
37+
}
38+
},
3139
"extra": {
3240
"laravel": {
3341
"providers": [
@@ -38,6 +46,9 @@
3846
}
3947
}
4048
},
49+
"config": {
50+
"sort-packages": true
51+
},
4152
"minimum-stability": "dev",
4253
"prefer-stable": true
4354
}

phpunit.xml.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
>
12+
<testsuites>
13+
<testsuite name="laravel-readable Test Suite">
14+
<directory suffix="Test.php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist processUncoveredFilesFromWhitelist="false">
19+
<directory suffix=".php">./src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

tests/ReadableTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Pharaonic\Laravel\Readable;
4+
5+
use Orchestra\Testbench\TestCase;
6+
7+
8+
class ReadableTest extends TestCase
9+
{
10+
public function testNumber()
11+
{
12+
$this->assertEquals('10,203,040', Readable::getNumber(10203040));
13+
}
14+
15+
public function testNumberToString()
16+
{
17+
if (!\extension_loaded('intl'))
18+
$this->fail('Intl extension has not been loaded.');
19+
20+
$this->assertEquals('seven thousand seven hundred twenty-one', Readable::getNumberToString(7721));
21+
}
22+
23+
public function testHumanNumber()
24+
{
25+
$this->assertEquals('77.7K', Readable::getHumanNumber(77700, true, 1));
26+
}
27+
28+
public function testDecimal()
29+
{
30+
$this->assertEquals('60,708.54', Readable::getDecimal(60708.54));
31+
}
32+
33+
public function testDecInt()
34+
{
35+
$this->assertEquals(70, Readable::getDecInt(70.0));
36+
}
37+
38+
public function testDate()
39+
{
40+
$this->assertEquals('24 April 2020', Readable::getDate('24-04-2020'));
41+
}
42+
43+
public function testTime()
44+
{
45+
$this->assertEquals('03:20 PM', Readable::getTime('15:20:22', true));
46+
}
47+
48+
public function testDateTime()
49+
{
50+
$this->assertEquals('Friday, April 24, 2020 05:20:30 PM', Readable::getDateTime('24-04-2020 17:20:30', true, true));
51+
}
52+
53+
public function testDiffDateTime()
54+
{
55+
$this->assertEquals('29 years before', Readable::getDiffDateTime('01-02-1993 19:00:00', '01-02-2022 19:00:00'));
56+
}
57+
58+
public function testTimeLength()
59+
{
60+
$this->assertEquals('3 months 29 minutes 37 seconds', Readable::getTimeLength(7777777));
61+
}
62+
63+
public function testDateTimeLength()
64+
{
65+
$this->assertEquals('29 years before', Readable::getDateTimeLength('01-02-1993 19:00:00', '01-02-2022 19:00:00'));
66+
}
67+
68+
public function testSize()
69+
{
70+
$this->assertEquals('7 KiB', Readable::getSize(1024 * 7, false));
71+
}
72+
}

0 commit comments

Comments
 (0)