/** * @test * @group acceptance */ public function it_takes_the_first_three_letters_of_a_standard_input_and_returns_all_the_existing_matches_for_accommodations() { // Given admin insert 3 hotels $hotel = new Hotel($this->hotelRepository->nextIdentity(), "Blue Hotel", 3, "double occupancy room with a view"); $this->hotelRepository->insert($hotel); $hotel = new Hotel($this->hotelRepository->nextIdentity(), "White Hotel", 4, "double occupancy room"); $this->hotelRepository->insert($hotel); $hotel = new Hotel($this->hotelRepository->nextIdentity(), "Red Hotel", 3, "single occupancy room"); $this->hotelRepository->insert($hotel); // and 2 apartments $apartment = new Apartment($this->apartmentRepository->nextIdentity(), "Beach Apartments", 10, 4); $this->apartmentRepository->insert($apartment); $apartment = new Apartment($this->apartmentRepository->nextIdentity(), "Sun and Beach Apartments", 50, 6); $this->apartmentRepository->insert($apartment); // when admin search for "tel" running console command: // php -f .\app\console.php search-accommodation tel $inputText = "tel"; $accommodationRepository = new InMemoryAccommodationRepository($this->hotelRepository, $this->apartmentRepository); $accommodations = $accommodationRepository->fullTextSearchShortedByName(substr($inputText, 0, 3)); $resultPrinter = new ResultPrinter(); ob_start(); $resultPrinter->printAccommodations($accommodations); $output = ob_get_contents(); ob_end_clean(); // then she should see: // * Blue Hotel, 3 stars, double occupancy room with a view, Valencia, Valencia // * Red Hotel, 3 stars, single occupancy room, Sanlucar, Cádiz // * White Hotel, 4 hotels, double occupancy room, Málaga, Málaga $this->assertEquals("Total: 3\n* Blue Hotel, 3 stars, double occupancy room with a view \n* Red Hotel, 3 stars, single occupancy room \n* White Hotel, 4 stars, double occupancy room \n", $output); }
$numAdultsFlatsPerFlat = $argv[4]; $command = new CreateApartmentCommand($name, $numFlats, $numAdultsFlatsPerFlat); // TODO: validate command $apartmentRepository = new MySqlApartmentRepository(new Config()); $createApartmentCommandHandler = new CreateApartmentCommandHandler($apartmentRepository); try { $createApartmentCommandHandler->handle($command); $output = "Apartment created\n"; } catch (\Exception $e) { $output = "Error trying to create the apartment: " . $e->getMessage(); } break; case 'search-accommodation': $inputText = $argv[2]; $hotelRepository = new MySqlHotelRepository(new Config()); $apartmentRepository = new MySqlApartmentRepository(new Config()); $accommodationRepository = new MySqlAccommodationRepository($hotelRepository, $apartmentRepository); $accommodations = $accommodationRepository->fullTextSearchShortedByName(substr($inputText, 0, 3)); if (!is_array($accommodations) || count($accommodations) == 0) { echo "No accommodations found\n"; } else { $resultPrinter = new ResultPrinter(); $resultPrinter->printAccommodations($accommodations); } break; default: echo "Invalid command name: {$commandName}.\n"; exit(2); } echo $output; }