public function testFullProcess() { parent::testFullProcess(); // nginxproxy $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/nginxproxy/acmephp.com.crt'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/nginxproxy/acmephp.com.key'); // Backup $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/private/acmephp.com/private.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/private/acmephp.com/public.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/certs/acmephp.com/cert.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/certs/acmephp.com/combined.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/certs/acmephp.com/chain.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/certs/acmephp.com/fullchain.pem'); // Backup nginxproxy $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/nginxproxy/acmephp.com.crt'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/backup/nginxproxy/acmephp.com.key'); // SFTP $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/private/_account/private.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/private/_account/public.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/private/acmephp.com/private.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/private/acmephp.com/public.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/certs/acmephp.com/fullchain.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/certs/acmephp.com/cert.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/certs/acmephp.com/chain.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/certs/acmephp.com/combined.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/nginxproxy/acmephp.com.crt'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/sftp/nginxproxy/acmephp.com.key'); }
public function testRenewalWithIssue() { parent::testFullProcess(); $command = $this->application->find('request'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'domain' => 'acmephp.com', '--server' => 'http://127.0.0.1:4000/directory', '--country' => 'FR', '--province' => 'Ile de France', '--locality' => 'Paris', '--organization' => 'Acme PHP', '--unit' => 'Sales', '--email' => '*****@*****.**', '--force' => true]); $requestDisplay = $commandTester->getDisplay(); $this->assertContains('Certificate renewed successfully!', $requestDisplay); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/private/acmephp.com/private.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/private/acmephp.com/public.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/certs/acmephp.com/cert.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/certs/acmephp.com/combined.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/certs/acmephp.com/chain.pem'); $this->assertFileExists(__DIR__ . '/../Cli/Fixtures/local/master/certs/acmephp.com/fullchain.pem'); /* * Mock monitoring handlers */ // Initialize container $parentReflection = new \ReflectionClass(AbstractCommand::class); $containerReflection = $parentReflection->getProperty('container'); $containerReflection->setAccessible(true); $containerReflection->setValue($command, null); $commandReflection = new \ReflectionObject($command); $initializer = $commandReflection->getMethod('initializeContainer'); $initializer->setAccessible(true); $initializer->invoke($command); // Replace handlers builders by mocks $handler = new TestHandler(); $handlerBuilder = $this->getMock(HandlerBuilderInterface::class); $handlerBuilder->expects($this->exactly(2))->method('createHandler')->willReturn($handler); /** @var ContainerInterface $container */ $container = $containerReflection->getValue($command); $container->set('monitoring.email', $handlerBuilder); $container->set('monitoring.slack', $handlerBuilder); // Introduce HTTP issue $container->set('http.raw_client', new Client(['handler' => new MockHandler([new RequestException('Error Communicating with Server', new Request('GET', 'test'))])])); // Set new container $containerReflection->setValue($command, $container); /* * Renewal with issue */ $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'domain' => 'acmephp.com', '--server' => 'http://127.0.0.1:4000/directory', '--country' => 'FR', '--province' => 'Ile de France', '--locality' => 'Paris', '--organization' => 'Acme PHP', '--unit' => 'Sales', '--email' => '*****@*****.**', '--force' => true]); $requestDisplay = $commandTester->getDisplay(); $this->assertNotContains('Certificate renewed successfully!', $requestDisplay); $records = $handler->getRecords(); $this->assertCount(2, $records); $this->assertSame(Logger::ALERT, $records[0]['level']); $this->assertSame('A critical error occured during certificate renewal', $records[0]['message']); $this->assertSame(Logger::ALERT, $records[1]['level']); $this->assertSame('A critical error occured during certificate renewal', $records[1]['message']); }