Symfony configuration for Apache

Edit /etc/hosts

127.0.0.1       symfony.io

Add VirtualHost in /etc/apache2/sites-available/symfony.conf


    ServerName symfony.io
    #ServerAlias www.domain.tld

    DocumentRoot /var/www/html/learningSymfony
    
        AllowOverride All
        Order Allow,Deny
        Allow from All

        
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ web/app_dev.php [QSA,L]
        
    

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    
        Options FollowSymlinks
    

    ErrorLog /var/log/apache2/learningSymfony.log
    CustomLog /var/log/apache2/learningSymfony.log combined

Create symlink to file configuration

ln -s /etc/apache2/sites-available/symfony.conf /etc/apache2/sites-enable/symfony.conf

Enable mod_rewrite in Apache:

sudo a2enmod rewrite

Restart apache:

sudo service apache2 restart

Go!

First steps mocking with PHPUnit

Our class:

class CanviPool
{
    public function retValue($val)
    {
        return $val;
    }
}

Our mocking class:

class CanviPoolTest extends TestBase
{
public function test_UT_ReturnValue()
{
// A mock object is created using CanviPool class
// The method 'retValue' will be mocked
$conConfig = $this->getMock('CanviPool', array('retValue'));

// We expect to use 'retValue' method ANY times in this test
// The mocked method is 'retValue'
// The mocked method will return the value 3
$conConfig
->expects($this->any())
->method('retValue')
->will($this->returnValue(3));

// We call the mocked method passing the required parameter
$res = $conConfig->retValue(1);
// Wen we compare the result with the value 3, the assert is true
$this->assertEquals(3, $res);

// We can do a new test
$res = $conConfig->retValue(1);
// And the result will be 3 again, because of the parameter ANY "->expects($this->any())"
// if insted of "any" the word was "once" this test would fail
$this->assertEquals(3, $res);
}
}