Componette

Componette

damejidlo

damejidlo / datetime-factory 2.0.0

Simple one-class lib for separation of NOW resolving.

download-cloud-line composer require damejidlo/datetime-factory

Downloads this Month Latest Stable Version

Motivation

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

This ultra-simple library provides service you can easily use and mock.

Install

composer require damejidlo/datetime-factory

And then just register it in your config.neon as a service.

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);
}
  • 2.0.0 2.0.0

    • Minimal required version of PHP is 7.1.
    • Use strict types and return types.
    • Revert removal of nette/utils.
    • DateTimeFactory is deprecated, use DateTimeImmutableFactory instead.
    • Use phpstan in CI build.
    • Use damejidlo/coding-standard in CI build.
  • 1.1 1.1

    Removed dependency on nette/utils
    added DateTimeImmutableFactory

  • 1.0.1 Welcome Nette 2.4!

    This release allows to install Nette 2.4

  • 1.0.0 First release

bar-chart-fill

Statistics

download-cloud-fill
106985
star-fill
7
bug-fill
0
flashlight-fill
6.1y
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.1)
nette/utils (^2.4@dev || ^3.0@dev)
Componette Componette felix@nette.org