AppKernel and DependencyInjection container in Symfony 2 tests

It's fairly simple to use app kernel and DI container in symfony tests, just require AppKernel.php:

 
require_once __DIR__.'/../../../../../../app/AppKernel.php';
 

and then boot your app in setUp method:

 
 
    private $container;
 
    public function setUp()
    {
        $this->app = new \AppKernel('test', true);
        $this->app->boot();
        $this->container = $this->app->getContainer();
    }
 

then, use a container where needed:

 
    public function testFoo()
    {
        $this->container->get('logger')->debug('Foo');
    }
 

Bash: how to copy permissions recursively

Imagine you were copying an, eg, virtual server from /server to /newserver, and messed permissions in /etc; thre's a way to copy permissions with this simple script:

 
#!/bin/bash
 
source=$1
target=$2
 
echo "Copy files from $source to $target"
 
cd $source
files=`find $source`
 
for file in $files
do
  #this is some bash voodoo - string part replacement
  targetFile=$target${file#$source}
  #stat command can accept -c parameter and return data in needed format
  #where %u and %g are numeric user/group ids, and %a - octal permissions
  permissions=`stat -c%a $file`
  ownership=`stat -c%u:%g $file`
  echo $targetFile to $ownership $permissions
  chmod $permissions $targetFile
  chown $ownership $targetFile
done
 

invoke this like

 
./permissions.sh /server/etc /newserver/etc
 

change %u:%g to %U:%G if you prefer string id's (www-data:www-data) more than numeric (0:0)