2017 © Pedro Peláez
 

symfony-bundle date-time-provider-bundle

Symfony bundle for `gsokol/date-time-provider` library

image

gsokol/date-time-provider-bundle

Symfony bundle for `gsokol/date-time-provider` library

  • Friday, September 8, 2017
  • by GSokol
  • Repository
  • 1 Watchers
  • 0 Stars
  • 164 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

DateTimeProviderBundle

Build Status, (*1)

Symfony bundle for gsokol/date-time-provider lib., (*2)

Install

Install via composer:, (*3)

composer require gsokol/date-time-provider-bundle

And in app/AppKernel.php:, (*4)

// app/AppKernel.php

// ...
class AppKernel Extends Kernel
{
    // ...
    public function registerBundles()
    {
        $bundles = [
            // ...
            new GSokol\DateTimeProviderBundle\DateTimePorviderBundle(),
            // ...
        ];
        // ...

Usage

Greedy request DateTime:, (*5)

doSomeStaff();
$timeOfRequestProcessionStart = $container->get('date-time-provider.greedy')->getRequestTime();

Lazy request DateTime:, (*6)

someLognOperation();
$currentTime = $container->get('date-time-provider.lazy')->getRequestTime();

Intervaling:, (*7)

$tomorrow = $container->get('date-time-provider.lazy')->getNewRequestTime()
    ->add(new \DateInterval('P1d'));

Benefits

Lat's think, you have a class method, that should return the next hour DateTime. Something like this:, (*8)


class NextHour { public function get() { return (new \DateTime()) ->add(new \DateInterval('PT1h')); } }

And now we need to cover it with unit tests. Oops, :hankey:!, (*9)

But if you inject providers:, (*10)

// class

use GSokol\DateTimeProvider\DateTimeProviderInterface;

class NextHour
{
    /**
     * @var DateTimeProviderInterface
     */
    private $dtProvider;

    public function __construct(DateTimeProviderInterface $dtProvider)
    {
        $this->dtProvider = $dtProvider;
    }

    public function get()
    {
        return $this->dtProvider->getCurrentTime()
            ->add(new \DateInterval('PT1h'));
    }
}
// test

use GSokol\DateTimeProvider\DateTimeProviderInterface;
use PHPUnit\Framework\TestCase;

class NextHourTest extends TestCase
{
    public function testGet()
    {
        $dtStub = (new \DateTime())->setTimestamp(0);
        $dtExp = (new \DateTime())->setTimestamp(3600);
        $dtProvider = $this->getMockBuilder(DateTimeProviderInterface)
            ->disableOriginalConstructor()
            ->setMethods(['getCurrentTime'])
            ->getMock();
        $dtProvider->expects($this->once())
            ->method('getCurrentTime')
            ->will($this->returnValue($dtStub));

        $target = new NextHour($dtProvider);

        $this->assertEquals($dtExp, $target->get());
    }
}

:+1:, (*11)

The Versions

08/09 2017

dev-master

9999999-dev

Symfony bundle for `gsokol/date-time-provider` library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Grigorii Sokolik

08/09 2017

1.0.0

1.0.0.0

Symfony bundle for `gsokol/date-time-provider` library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Grigorii Sokolik