2017 © Pedro Peláez
 

library datetime-factory

image

damejidlo/datetime-factory

  • Thursday, February 8, 2018
  • by Achse
  • Repository
  • 12 Watchers
  • 6 Stars
  • 32,492 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Downloads this Month Latest Stable Version , (*1)

Motivation

In our application you should never obtain NOW via new DateTime() or from SQL NOW(). Because it's unmockable and therefore untestable., (*2)

This ultra-simple library provides service you can easily use and mock., (*3)

Install

composer require damejidlo/datetime-factory

And then just register it in your config.neon as a service., (*4)

Example (of mocking in tests)

public function testXyz(\DateTimeImmutable $subjectTime)
{
    $container = $this->createContainer();
    $dateTimeFactory = Mockery::mock(DateTimeFactoryImmutable::class);
    $dateTimeFactory->shouldReceive('getNow')->andReturn($subjectTime);
    $container->removeService('dateTimeFactory');
    $container->addService('dateTimeFactory', $dateTimeFactory);
}

The Versions

07/11 2016

1.1

1.1.0.0

  Sources   Download

MIT

The Requires

  • php >= 5.6.0

 

The Development Requires

04/05 2016

1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

01/04 2016

1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires