PHP code example of shopery / datetime
1. Go to this page and download the library: Download shopery/datetime library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shopery / datetime example snippets
use Shopery\DateTime\DateTime;
use DateTime as NativeDateTime;
class Coupon
{
private $expiredTime;
public function __construct(NativeDateTime $expiredTime)
{
$this->expiredTime = $expiredTime;
}
public function hasExpired()
{
return DateTime::now() > $this->expiredTime;
}
}
class CouponTest
{
public function test_has_expired()
{
$coupon = new Coupon(DateTime::create('yesterday'));
$this->assertTrue($coupon->hasExpired());
$frozenTime = DateTime::create('a month ago');
DateTime::freeze($frozenTime);
$this->assertFalse($coupon->hasExpired());
DateTime::unfreeze();
}
}
class MyTest
{
/**
* @freezeTime
*/
public function test_frozen_in_current_time()
{
}
/**
* @freezeTime 2015-01-31 08:30:00
*/
public function test_frozen_in_a_given_date()
{
}
/**
* @freezeTime first monday of January last year
*/
public function test_frozen_in_a_relative_date()
{
}
public function test_this_is_not_frozen()
{
}
}