Skip to content

Commit

Permalink
Merge branch 'add-testing-env'
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeiropaulor committed Jul 6, 2014
2 parents e063a46 + 1ab611f commit 787e08b
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 58 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
composer.lock
phpunit.xml
vendor
log
Tests/App/cache
Tests/App/logs

.idea
17 changes: 7 additions & 10 deletions Command/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace BFOS\SyncContentBundle\Command;

use BFOS\SyncContentBundle\Server\ServerRegister;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -57,32 +58,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
$servername = $input->getArgument('server');

/**
* @var \BFOS\SyncContentBundle\Manager $manager
* @var ServerRegister $register
*/
$manager = $this->getContainer()->get('bfos_sync_content.manager');

$server = $manager->getServer($servername);


$this->synchronize_content($server, $manager, $output);
$register = $this->getContainer()->get('bfos_sync_content.server_register');

$server = $register->getServer($servername);

$this->synchronize_content($server, $register, $output);

$output->writeln('Synchronization was successful.');
return true;

}


protected function synchronize_content(Server $server, $manager, OutputInterface $output){
protected function synchronize_content(Server $server, ServerRegister $register, OutputInterface $output){

// Synchronize files

$pathLocal = '.';
$pathRemote = $server->getUser() . '@' . $server->getHost() . ':' . $server->getDir();
$port = $server->getPort();

$options = $manager->getOptions();
$options = $register->getOptions();

$output->writeln('Deploying app...');
$results = array();
Expand Down
2 changes: 1 addition & 1 deletion Command/ShowServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$manager = $this->getContainer()->get('bfos_sync_content.manager');
$manager = $this->getContainer()->get('bfos_sync_content.server_register');
$server = $input->getArgument('server');

if (null === $server) {
Expand Down
2 changes: 1 addition & 1 deletion Command/SyncFromCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @var \BFOS\SyncContentBundle\Manager $manager
*/
$manager = $this->getContainer()->get('bfos_sync_content.manager');
$manager = $this->getContainer()->get('bfos_sync_content.server_register');

$server = $manager->getServer($servername);

Expand Down
2 changes: 1 addition & 1 deletion Command/SyncToCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
/**
* @var \BFOS\SyncContentBundle\Manager $manager
*/
$manager = $this->getContainer()->get('bfos_sync_content.manager');
$manager = $this->getContainer()->get('bfos_sync_content.server_register');

$server = $manager->getServer($servername);

Expand Down
19 changes: 0 additions & 19 deletions Controller/DefaultController.php

This file was deleted.

2 changes: 1 addition & 1 deletion DependencyInjection/BFOSSyncContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

$manager = $container->getDefinition('bfos_sync_content.manager');
$manager = $container->getDefinition('bfos_sync_content.server_register');

// Options
$manager->addMethodCall('setOptions', array($config['options']));
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<parameters>
<parameter key="bfos_sync_content.server_loader.class">BFOS\SyncContentBundle\Loader\ServerLoader</parameter>
<parameter key="bfos_sync_content.manager.class">BFOS\SyncContentBundle\Manager</parameter>
<parameter key="bfos_sync_content.server_register.class">BFOS\SyncContentBundle\Server\ServerRegister</parameter>
</parameters>

<services>
<service id="bfos_sync_content.server_loader" class="%bfos_sync_content.server_loader.class%">
</service>
<service id="bfos_sync_content.manager" class="%bfos_sync_content.manager.class%">
<service id="bfos_sync_content.server_register" class="%bfos_sync_content.server_register.class%">
<argument type="service" id="bfos_sync_content.server_loader" />
</service>
</services>
Expand Down
10 changes: 5 additions & 5 deletions Manager.php → Server/ServerRegister.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace BFOS\SyncContentBundle;
namespace BFOS\SyncContentBundle\Server;

use BFOS\SyncContentBundle\Loader\LoaderInterface;
use BFOS\SyncContentBundle\Server\Server;

class Manager {
class ServerRegister {
/**
* @var array
*/
Expand Down Expand Up @@ -46,7 +46,7 @@ public function loadServers($filename)
* @param string $name
* @param Server $server
*
* @return Manager
* @return ServerRegister
*/
public function addServer($name, $server)
{
Expand All @@ -68,7 +68,7 @@ public function addServer($name, $server)
*
* @param array $servers
*
* @return Manager
* @return ServerRegister
*/
public function setServers(array $servers)
{
Expand All @@ -84,7 +84,7 @@ public function setServers(array $servers)
*
* @param string $name
*
* @return Manager
* @return ServerRegister
*/
public function removeServer($name)
{
Expand Down
28 changes: 28 additions & 0 deletions Tests/App/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace BFOS\SyncContentBundle\Tests\App;

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
// new Symfony\Bundle\SecurityBundle\SecurityBundle(),
// new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),

// bundle to test
new BFOS\SyncContentBundle\BFOSSyncContentBundle(),
);

return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config.yml');
}
}
47 changes: 47 additions & 0 deletions Tests/App/config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
framework:
translator: { fallback: en }
secret: secret
# router:
# resource: "%kernel.root_dir%/config/routing.yml"
# strict_requirements: %kernel.debug%
templating:
engines: ['php']
default_locale: en
session: ~
test: ~

bfos_sync_content:
options: # Global options
deployment:
rsync_exclude: "%kernel.root_dir%/config/rsync_exclude.txt"
pre_local_commands:
- 'php app/console assetic:dump'
post_local_commands:
- 'rm -rf web/js web/css'
#pre_remote_commands:
# - './c'
post_remote_commands:
- 'php app/console cache:clear --env=prod --no-debug --no-warmup'
- 'php app/console doctrine:schema:update --force --env=prod'
- 'php app/console assets:install web --symlink'
sync_content:
content:
- "web/uploads"
# servers: "%kernel.root_dir%/config/deployment_sync_content.yml"
#
servers:
staging:
host: staging.mysite.com
port: 22
user: mysite
dir: /home/user/mysite
options : # Server options, override the globals
rsync_options: '-azC --force --delete --verbose --progress'
production:
host: www.mysite.com
port: 22
user: mysite
dir: /home/user/mysite
options : # Server options, override the globals
rsync_options: '-azC --force --delete --verbose --progress'

17 changes: 0 additions & 17 deletions Tests/Controller/DefaultControllerTest.php

This file was deleted.

25 changes: 25 additions & 0 deletions Tests/Server/ServerRegisterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace BFOS\SyncContentBundle\Tests\Command;


use BFOS\SyncContentBundle\Loader\ServerLoader;
use BFOS\SyncContentBundle\Server\Server;
use BFOS\SyncContentBundle\Server\ServerRegister;

class ServerRegisterTest extends \PHPUnit_Framework_TestCase
{
public function testAddServerToServersListSuccessfully()
{
// create a server register
$register = new ServerRegister(new ServerLoader());

// create a server
$server = new Server('www.test.com', 'webtest', '/home/vagrant', '123123');

// add a server to register
$register->addServer('srv1', $server);

// test the server was added
$this->assertEquals(1, count($register->getServers()), 'Server not added.');
}
}
24 changes: 24 additions & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$loader = @include __DIR__ . '/../vendor/autoload.php';
if (!$loader) {
die(<<<'EOT'
You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install
EOT
);
}

passthru(sprintf('rm -rf %s/App/cache', __DIR__));
spl_autoload_register(function($class) {
if (0 === strpos($class, 'BFOS\\SyncContentBundle\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 2)).'.php';
if (!stream_resolve_include_path($path)) {
return false;
}
require_once $path;

return true;
}
});
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.2"
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.2",
"symfony/finder": ">=2.2.0",
"symfony/console": "2.6.*@dev"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-0": { "BFOS\\SyncContentBundle": "" }
Expand Down
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
<php>
<server name="KERNEL_DIR" value="Tests/App" />
</php>

<testsuites>
<testsuite name="BFOSSyncContentBundle test suite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit 787e08b

Please sign in to comment.