| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace ConferenceTools\Tickets\Domain\Service\Availability; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Carnage\Cqrs\Persistence\ReadModel\RepositoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use ConferenceTools\Tickets\Domain\Service\Availability\Filters\FilterInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use ConferenceTools\Tickets\Domain\ValueObject\DiscountType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\Common\Collections\ArrayCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Mockery\Adapter\Phpunit\MockeryTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use ConferenceTools\Tickets\Domain\Finder\TicketCounterInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use ConferenceTools\Tickets\Domain\ReadModel\TicketCounts\TicketCounter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use ConferenceTools\Tickets\Domain\Service\Configuration; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Mockery as m; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class DiscountCodeAvailabilityTest extends MockeryTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var Configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $config; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var ArrayCollection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $ticketCounters; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @var FilterInterface[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $filters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function __construct($name = null, array $data = array(), $dataName = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         parent::__construct($name, $data, $dataName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->config = Configuration::fromArray([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             'tickets' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             'discountCodes' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                 '50off' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     'type' => DiscountType\Percentage::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     'options' => ['percentage' => 50], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     'name' => '50% Off', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                     'metadata' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                         'availableFrom' =>(new \DateTime)->sub(new \DateInterval('P2D')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                         'availableTo' =>(new \DateTime)->sub(new \DateInterval('P1D')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 '5offone' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                     'type' => DiscountType\Fixed::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     'options' => ['net' => 500], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     'name' => '$5 Off', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     'metadata' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                         'availableFrom' =>(new \DateTime)->sub(new \DateInterval('P1D')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                         'availableTo' =>(new \DateTime)->add(new \DateInterval('P1D')), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 '5offall' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                     'type' => DiscountType\FixedPerTicket::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                     'options' => ['gross' => 500], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                     'name' => '$5 Off', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             'financial' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 'taxRate' => 10, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 'currency' => 'GBP', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 'displayTax' => true | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->filters = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             new Filters\DiscountByDate($this->config), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 76 |  | View Code Duplication |     public function testFetchAllAvailableDiscountCodes() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $mockFinder = m::mock(RepositoryInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $mockFinder->shouldReceive('matching')->andReturn(new ArrayCollection($this->config->getDiscountCodes())); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $sut = new DiscountCodeAvailability($mockFinder, ...$this->filters); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $result = $sut->fetchAllAvailableDiscountCodes(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         self::assertTrue($result->count() === 2, 'The expected number of discount codes was not returned'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         self::assertFalse($result->contains($this->config->getDiscountCodes()['50off']), 'Expired code was included in results'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @dataProvider provideIsAvailable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 93 |  | View Code Duplication |     public function testIsAvailable($code, $expected) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         $mockFinder = m::mock(RepositoryInterface::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         $mockFinder->shouldReceive('matching')->andReturn(new ArrayCollection($this->config->getDiscountCodes())); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         $sut = new DiscountCodeAvailability($mockFinder, ...$this->filters); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         self::assertEquals($expected, $sut->isAvailable($code)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function provideIsAvailable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             [$this->config->getDiscountCodes()['50off'], false], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             [$this->config->getDiscountCodes()['5offone'], true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             [$this->config->getDiscountCodes()['5offall'], true], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths