Symfony testing

Updated: 16 July 2023

Testing (Symfony Docs)

Unit Tests

These tests ensure that individual units of source code (e.g. a single class or a method in a class) behave as intended. No different from writing standard PHPUnit unit tests.

Integration Tests

These tests test a combination of classes and commonly interact with Symfony’s service container. These tests do not yet cover the fully working application.

Application Tests

Verify the behavior of a complete application. They make HTTP requests (both real and simulated ones) and test that the response is as expected.

The output of the make:test command supplies a useful summary too

root@5b8333e33939:/var/www/html# bin/console make:test

 Which test type would you like?:
  [TestCase       ] basic PHPUnit tests
  [KernelTestCase ] basic tests that have access to Symfony services
  [WebTestCase    ] to run browser-like scenarios, but that don't execute JavaScript code
  [ApiTestCase    ] to run API-oriented scenarios
  [PantherTestCase] to run e2e scenarios, using a real-browser or HTTP client and a real web server
 >

Composer tool itself

Updated: 17 January 2023

Install Composer phar

curl -sS https://getcomposer.org/installer | php

Circumvent php memory limit

php -d memory_limit=-1 composer.phar install

Up / downgrade Composer itself

composer self-update --help
composer self-update --1
composer self-update --2

Composer in Docker

Updated: 17 January 2023

Require a new project as a dependency

docker run --rm \
    -v $(pwd):/app \
    composer/composer:latest \
    require slim/slim "^3.0"

Install all dependencies in a project

docker run --rm --interactive --tty --volume $PWD:/app composer install

PHP and Docker

Updated: 19 November 2022

Run a php script

docker run -it --rm --name my-running-script \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
php:7.4-cli php script.php

Run the php development server

docker run -it --rm --name php-server \
-v "$PWD":/usr/src/myapp \
-w /usr/src/myapp \
-p 8000:8000 \
php:7.4-cli php -S 0.0.0.0:8000

php file permissions

Updated: 10 September 2022

Set folder and file permissions for a php project

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;