Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Created March 3, 2018 09:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Making domain services testable
<?php
namespace Sps\Intranet\Domain\Model\Offer;
use Sps\Intranet\Domain\Model\Partner\PartnerId;
use Sps\Intranet\Infrastructure\Projection\Mongo\OfferReadModelFinder;
/**
* Class OfferNumberGenerator
* @package Sps\Intranet\Domain\Model\Offer
*/
class OfferNumberGenerator
{
/** @var OfferReadModelFinder $offers */
private $offers;
/**
* OfferNumberGenerator constructor.
* @param OfferReadModelFinder $offers
*/
public function __construct(OfferReadModelFinder $offers)
{
$this->offers = $offers;
}
/**
* @param PartnerId $partnerId
* @return OfferNumber
*/
function generate(PartnerId $partnerId)
{
$currentOfferNumber = $this->offers->currentOfferNumber($partnerId);
return null !== $currentOfferNumber ? $currentOfferNumber->next() : OfferNumber::generate();
}
}
@webdevilopers
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment