public function testItDisplaysExceptionsAsErrorMessages()
 {
     $expectedMessage = 'Dummy Exception';
     $this->mockProductStatusAdapter->method('disableProductWithSku')->willThrowException(new \Exception($expectedMessage));
     $this->mockOutput->expects($this->once())->method('writeln')->with($this->stringStartsWith('<error>' . $expectedMessage));
     $this->command->run($this->mockInput, $this->mockOutput);
 }
 public function testItDisplaysExceptionsAsAnErrorMessage()
 {
     $expectedMessage = 'Dummy Exception';
     $this->mockOutput->expects($this->once())->method('writeln')->with('<error>' . $expectedMessage . '</error>');
     $this->mockProductStatusAdapter->method('enableProductWithSku')->willThrowException(new \Exception($expectedMessage));
     $this->mockInput->method('getArgument')->willReturn('test');
     $this->command->run($this->mockInput, $this->mockOutput);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $sku = $input->getArgument('sku');
         $this->productStatusAdapter->enableProductWithSku($sku);
         $output->writeln(sprintf('<info>Status of product "%s": enabled</info>', $sku));
     } catch (\Exception $exception) {
         $output->writeln('<error>' . $exception->getMessage() . '</error>');
     }
 }
 /**
  * @param string $sku
  * @param string $status "enabled" or "disabled"
  * @return string
  */
 public function set($sku, $status)
 {
     $this->validateStatus($status);
     if (ProductStatusAdapterInterface::ENABLED === $status) {
         $this->productStatusAdapter->enableProductWithSku($sku);
     } else {
         $this->productStatusAdapter->disableProductWithSku($sku);
     }
     return $status;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         $sku = $input->getArgument('sku');
         $result = $this->productStatusAdapter->getStatusForProductsMatchingSku($sku);
         if (empty($result)) {
             $output->writeln(sprintf('<comment>No products matching "%s" found</comment>', $sku));
         } else {
             array_map(function ($sku, $status) use($output) {
                 $output->writeln(sprintf('<info>Status of product "%s": %s</info>', $sku, $status));
             }, array_keys($result), $result);
         }
     } catch (\Exception $exception) {
         $output->writeln('<error>' . $exception->getMessage() . '</error>');
     }
 }
 public function testItDisplaysTheStatusForAllReturnedProducts()
 {
     $this->mockProductStatusAdapter->method('getStatusForProductsMatchingSku')->willReturn(['test1' => ProductStatusAdapterInterface::ENABLED, 'test2' => ProductStatusAdapterInterface::DISABLED]);
     $this->mockOutput->expects($this->exactly(2))->method('writeln')->withConsecutive([$this->stringContains('Status of product "test1": ' . ProductStatusAdapterInterface::ENABLED)], [$this->stringContains('Status of product "test2": ' . ProductStatusAdapterInterface::DISABLED)]);
     $this->command->run($this->mockInput, $this->mockOutput);
 }
 public function testItDelegatesDisablingProductsToTheProductStatusAdapter()
 {
     $this->mockProductStatusAdapter->expects($this->once())->method('disableProductWithSku');
     $this->statusManagement->set('test', ProductStatusAdapterInterface::DISABLED);
 }