Merge pull request #31 from imanghafoori1/tests

adding tests
This commit is contained in:
hekmatinasser authored and GitHub committed 2019-08-29 15:10:17 +04:30
commit d7f4959711
8 files changed
+2989 -5

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
vendor/
.idea/
*.phpunit.result.cache
*.bat
+38
View File
@@ -0,0 +1,38 @@
language: php
sudo: true
matrix:
include:
- php: 7.2
env: LARAVEL_VERSION=5.1.*
- php: 7.2
env: LARAVEL_VERSION=5.3.*
- php: 7.2
env: LARAVEL_VERSION=5.5.*
- php: 7.2
env: LARAVEL_VERSION=5.6.*
- php: 7.2
env: LARAVEL_VERSION=5.7.*
- php: 7.2
env: LARAVEL_VERSION=5.7.*
- php: 7.3
env: LARAVEL_VERSION=5.7.*
- php: 7.2
env: LARAVEL_VERSION=5.8.*
- php: 7.3
env: LARAVEL_VERSION=5.8.*
before_install:
- composer self-update --stable -n
install:
- travis_retry composer install --no-suggest
script:
- vendor/bin/phpunit --coverage-clover clover.xml;
after_script:
- wget https://scrutinizer-ci.com/ocular.phar;
- php ocular.phar code-coverage:upload --format=php-clover clover.xml;
- bash <(curl -s https://codecov.io/bash)
+12 -3
View File
@@ -12,9 +12,13 @@
"require": { "require": {
"php": ">=5.5", "php": ">=5.5",
"hekmatinasser/notowo": "^1.0", "hekmatinasser/notowo": "^1.0",
"illuminate/validation": "^5" "illuminate/validation": "^5",
}, "illuminate/support": "^5"
"require-dev" : {}, },
"require-dev" : {
"phpunit/phpunit": "7.2.*",
"mockery/mockery": "^1.0"
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Hekmatinasser\\Verta\\": "src" "Hekmatinasser\\Verta\\": "src"
@@ -23,6 +27,11 @@
"src/helpers.php" "src/helpers.php"
] ]
}, },
"autoload-dev": {
"psr-4": {
"Hekmatinasser\\VertaTests\\": "tests"
}
},
"minimum-stability": "dev", "minimum-stability": "dev",
"extra": { "extra": {
"laravel": { "laravel": {
Generated
+2830
View File
File diff suppressed because it is too large. Load diff
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".blade.php">./src/</directory>
</exclude>
</whitelist>
</filter>
<php>
<!--
<env name="REDIS_HOST" value="127.0.0.1" />
<env name="REDIS_PORT" value="6379" />
-->
</php>
</phpunit>
+3 -2
View File
@@ -13,6 +13,7 @@ namespace Hekmatinasser\Verta;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use Illuminate\Support\Carbon;
use InvalidArgumentException; use InvalidArgumentException;
use Hekmatinasser\Notowo\Notowo; use Hekmatinasser\Notowo\Notowo;
@@ -246,7 +247,7 @@ class Verta extends DateTime {
*/ */
public function __construct($datetime = null, $timezone = null) { public function __construct($datetime = null, $timezone = null) {
if ($datetime === null) { if ($datetime === null) {
$instance = time(); $instance = Carbon::now()->getTimestamp();
} }
elseif (is_string($datetime)){ elseif (is_string($datetime)){
$object = date_create($datetime); $object = date_create($datetime);
@@ -508,7 +509,7 @@ class Verta extends DateTime {
public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null) public static function createGregorian($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $timezone = null)
{ {
$now = date('Y-n-j-G-i-s', time()); $now = date('Y-n-j-G-i-s', Carbon::now()->getTimestamp());
$defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now)); $defaults = array_combine(array('year', 'month', 'day', 'hour', 'minute', 'second'), explode('-', $now));
$year = $year === null ? intval($defaults['year']) : $year; $year = $year === null ? intval($defaults['year']) : $year;
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace Hekmatinasser\VertaTests;
use Hekmatinasser\Verta\Facades\Verta as VertaFacade;
use Hekmatinasser\Verta\Verta;
use Illuminate\Support\Carbon;
use PHPUnit\Framework\TestCase;
class SampleTest extends TestCase
{
public function testVertaNow()
{
Carbon::setTestNow('2019-01-01 00:00:00');
$shamsiDate = (string)Verta::now();
$this->assertEquals('1397-10-11 00:00:00', $shamsiDate);
}
public function testVertaNow2()
{
Carbon::setTestNow('2019-01-01 00:00:01');
$shamsiDate = (string)Verta::now();
$this->assertEquals('1397-10-11 00:00:01', $shamsiDate);
}
public function testYesterday()
{
Carbon::setTestNow('2019-01-01 10:20:11');
$shamsiDate = (string)Verta::yesterday();
$this->assertEquals('1397-10-10 00:00:00', $shamsiDate);
$shamsiDate = (string)Verta::tomorrow();
$this->assertEquals('1397-10-12 00:00:00', $shamsiDate);
$shamsiDate = (string)Verta::today();
$this->assertEquals('1397-10-11 00:00:00', $shamsiDate);
}
public function testCreateFromString()
{
$v = new Verta('2019-01-01 10:20:11');
$this->assertEquals('1397-10-11 10:20:11', (string)$v);
$v = new Verta('2019-01-02 10:20:11');
$this->assertEquals('1397-10-12 10:20:11', (string)$v);
$v = Verta::instance('2019-01-01 10:20:11');
$this->assertEquals('1397-10-11 10:20:11', (string)$v);
$app = ['verta' => new Verta];
VertaFacade::setFacadeApplication($app);
$v = VertaFacade::instance('2019-01-01 10:20:11');
$this->assertEquals('1397-10-11 10:20:11', (string)$v);
}
public function testDatetime()
{
$d = new \DateTime('2019-01-01 10:20:11');
$f1 = new Verta($d);
$f2 = new Verta('2019-01-01 10:20:11');
$this->assertEquals((string)$f1, (string)$f2);
}
}
+1
View File
@@ -0,0 +1 @@
<?php