BaseTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use Docker\Composer\FileFormat2;
  3. use PHPUnit\Framework\TestCase;
  4. use Symfony\Component\Yaml\Yaml;
  5. require __DIR__ . "/../../../autoload.php";
  6. class BaseTest extends TestCase
  7. {
  8. public function testSimpleUsage()
  9. {
  10. $composer = new FileFormat2();
  11. $composer->addService("Base")->image("ubuntu:16.10");
  12. $composer->addService("Ftth")->image("ubuntu:17.10");
  13. $composer->addService("ubuntu")->image("ubuntu");
  14. $composer->addService("custom")->build("./custom");
  15. $composer->addService("test1")->build("./custom1")->addVolumes('volumen_test1_test2', '/opt/test1');
  16. $composer->addService("test2")->build("./custom2")->addVolumes('volumen_test1_test2', '/opt/test2')
  17. ->network('flowdat3')->ipv4_address("172.172.172.2");
  18. $composer->getVolumes()->addVolumen('volumen_test1_test2', 'local');
  19. $nc = new \Docker\Composer\NetworkConfig();
  20. $nc->addDriver()->addSubnetGateway();
  21. $composer->getNetwork()->addDriver('flowdat3')->addConfig('flowdat3', $nc);
  22. $rtr = Yaml::parse($composer->render());
  23. $this->assertEquals(
  24. array(
  25. "version" => "2.2",
  26. "services" => array(
  27. "Base" => array("image" => "ubuntu:16.10"),
  28. "Ftth" => array("image" => "ubuntu:17.10"),
  29. "ubuntu" => array("image" => "ubuntu"),
  30. "custom" => array("build" => array("context" => "./custom")),
  31. "test1" => array("build" => array("context" => "./custom1"), "volumes" => array('volumen_test1_test2:/opt/test1')),
  32. "test2" => array("build" => array("context" => "./custom2"), "volumes" => array('volumen_test1_test2:/opt/test2'),
  33. "networks" => array("flowdat3" => array("ipv4_address" => "172.172.172.2"))),
  34. ),
  35. "volumes" => array('volumen_test1_test2' => array('driver' => 'local')),
  36. "networks" => array('flowdat3' => array('driver' => 'bridge',
  37. 'ipam' => array('driver' => 'default',
  38. 'config' => array(array('subnet' => '172.172.172.0/16'), array('gateway' => '172.172.172.1')))))
  39. ), $rtr);
  40. }
  41. }