Luciano Andrade 8 years ago
parent
commit
d552d3ea50
5 changed files with 1493 additions and 7 deletions
  1. 1 0
      .gitignore
  2. 5 2
      composer.json
  3. 1452 2
      composer.lock
  4. 15 3
      src/Docker/Composer/FileFormat2.php
  5. 20 0
      test/BaseTest.php

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/vendor/

+ 5 - 2
composer.json

@@ -5,12 +5,15 @@
         "symfony/yaml": "^3.3"
     },
     "autoload": {
-        "psr-4": {"Docker\\": "src/"}
+        "psr-4": {"Docker\\": "src/Docker/"}
     },
     "authors": [
         {
             "name": "Luciano Andrade",
             "email": "andrade.luciano@gmail.com"
         }
-    ]
+    ],
+    "require-dev": {
+        "phpunit/phpunit": "^6.2"
+    }
 }

File diff suppressed because it is too large
+ 1452 - 2
composer.lock


+ 15 - 3
src/Docker/Composer/FileFormat2.php

@@ -1,7 +1,9 @@
 <?php
 
 namespace Docker\Composer;
-use Extension;
+use Symfony\Component\Yaml\Yaml;
+
+use Exception;
 
 class NetworkService{
 	protected $name;
@@ -654,16 +656,18 @@ class Service{
 		$this->config["working_dir"] = $working_dir;
 		return $this;
 	}
+
+	function getConfig(){ return $this->config;}
 }
 
-class ServiceNotFoundException extends Extension
+class ServiceNotFoundException extends \Exception
 {
 	function __construct($name){
 		parent::__construct("Service $name not found");
 	}
 }
 
-class FileFormat2 
+class FileFormat2
 {
 	/**
          * path of the docker-compose.yml
@@ -686,6 +690,14 @@ class FileFormat2
 		if(!$this->services[$name]) throw new ServiceNotFoundException($name);
 		return $this->services[$name];
         }
+
+	function render(){
+		$rtr = array("version" => "2.2", "services" => array());
+		foreach($this->services as $name => $service){
+			$rtr["services"][$name] = $service->getConfig();
+		}
+		return  Yaml::dump($rtr, 3, 2);
+	}
 }
 
 

+ 20 - 0
test/BaseTest.php

@@ -0,0 +1,20 @@
+<?php
+use PHPUnit\Framework\TestCase;
+use Docker\Composer\FileFormat2;
+
+require __DIR__."/../vendor/autoload.php";
+
+
+
+class BaseTest extends TestCase
+{
+    public function testPushAndPop()
+    {
+	$composer = new FileFormat2();
+	$composer->addService("Base")->image("ubuntu:16.10");
+
+	$composer->addService("Ftth")->image("ubuntu:17.10");
+
+	echo $composer->render();
+    }
+}