adding tests

This commit is contained in:
imanghafoori committed 2019-08-23 23:16:12 +04:30
1 parent c4abd7a621
commit ecd0ea7ad0
7 files changed
+2950 -4

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
vendor/
.idea/
*.phpunit.result.cache
*.bat
+11 -2
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" : {
"phpunit/phpunit": "^7.5|^8.0",
"mockery/mockery": "^1.0"
}, },
"require-dev" : {},
"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