Symfony2. Unit testing by Vadim Kharitonov

49
SYMFONY 2. PHPUNIT Vadim Kharitonov

description

Minsk Symfony: встреча в Марте

Transcript of Symfony2. Unit testing by Vadim Kharitonov

Page 1: Symfony2. Unit testing by Vadim Kharitonov

SYMFONY 2.PHPUNIT

Vadim Kharitonov

Page 2: Symfony2. Unit testing by Vadim Kharitonov
Page 3: Symfony2. Unit testing by Vadim Kharitonov

1. INSTALLATION

Page 4: Symfony2. Unit testing by Vadim Kharitonov

1.1 OS PACKAGE# apt-get install phpunit

Page 5: Symfony2. Unit testing by Vadim Kharitonov

1.2 PHPUNIT.PHAR$ wget https://phar.phpunit.de/phpunit.phar

$ chmod +x phpunit.phar

Page 6: Symfony2. Unit testing by Vadim Kharitonov

1.3 COMPOSER$ ./composer.phar require

'phpunit/phpunit=4.1.*'

Page 7: Symfony2. Unit testing by Vadim Kharitonov

1.4 PEAR# pear config-set auto_discover 1

# pear install pear.phpunit.de/PHPUnit

Page 8: Symfony2. Unit testing by Vadim Kharitonov

2. LET'S BATTLE

Page 9: Symfony2. Unit testing by Vadim Kharitonov

2.1 ENTITY

Page 10: Symfony2. Unit testing by Vadim Kharitonov

ENTITY\USER

Page 11: Symfony2. Unit testing by Vadim Kharitonov

TESTS\ENTITY\USERTEST

Page 12: Symfony2. Unit testing by Vadim Kharitonov

2.2 REPOSITORY

Page 13: Symfony2. Unit testing by Vadim Kharitonov

COMPOSER.JSON

Page 14: Symfony2. Unit testing by Vadim Kharitonov

APPKERNEL

Page 15: Symfony2. Unit testing by Vadim Kharitonov

CONFIG_TEST.YML

Page 16: Symfony2. Unit testing by Vadim Kharitonov

REPOSITORY\USERREPOSITORY

Page 17: Symfony2. Unit testing by Vadim Kharitonov

TESTS\REPOSITORY\USERREPOSITORYTEST

Page 18: Symfony2. Unit testing by Vadim Kharitonov

TESTS\REPOSITORY\FIXTURES\LOADUSERDATA

Page 19: Symfony2. Unit testing by Vadim Kharitonov

2.3 CONTROLLER

Page 20: Symfony2. Unit testing by Vadim Kharitonov

CONTROLLER\DEMOCONTROLLER

Page 21: Symfony2. Unit testing by Vadim Kharitonov

TESTS\CONTROLLER\DEMOCONTROLLERTEST

Page 22: Symfony2. Unit testing by Vadim Kharitonov

2.4 CONSOLE COMMANDS

Page 23: Symfony2. Unit testing by Vadim Kharitonov

COMMAND\HELLOWORLDCOMMAND

Page 24: Symfony2. Unit testing by Vadim Kharitonov

TESTS\COMMAND\HELLOWORLDCOMMANDTEST

Page 25: Symfony2. Unit testing by Vadim Kharitonov

2.5 FORMS

Page 26: Symfony2. Unit testing by Vadim Kharitonov

FORM\USERTYPE

Page 27: Symfony2. Unit testing by Vadim Kharitonov

TESTS\FORM\USERTYPETEST

Page 28: Symfony2. Unit testing by Vadim Kharitonov

2.6 EXTENSIONS

Page 29: Symfony2. Unit testing by Vadim Kharitonov

DEPENDENCYINJECTION\CONFIGURATION

Page 30: Symfony2. Unit testing by Vadim Kharitonov

DEPENDENCYINJECTION\ACMEDEMOEXTENSION

Page 31: Symfony2. Unit testing by Vadim Kharitonov

TESTS\DEPENDENCYINJECTION\ACMEDEMOEXTENSIONTEST

Page 32: Symfony2. Unit testing by Vadim Kharitonov

2.7 EVENT LISTENERS

Page 33: Symfony2. Unit testing by Vadim Kharitonov

EVENTLISTENERS\USERNOTIFIERLISTENER

Page 34: Symfony2. Unit testing by Vadim Kharitonov

EVENTS\USEREVENT

Page 35: Symfony2. Unit testing by Vadim Kharitonov

RESOURCES\CONFIG\SERVICES.XML

Page 36: Symfony2. Unit testing by Vadim Kharitonov

TESTS\EVENTLISTENERS\USERNOTIFIERLISTENERTEST

Page 37: Symfony2. Unit testing by Vadim Kharitonov

2.8 TWIG EXTENSIONS

Page 38: Symfony2. Unit testing by Vadim Kharitonov

RESOURCES\CONFIG\SERVICES.XML

Page 39: Symfony2. Unit testing by Vadim Kharitonov

TWIG\EXTENSION\SQREXTENSION

Page 40: Symfony2. Unit testing by Vadim Kharitonov

TESTS\TWIG\EXTENSION\SQREXTENSIONTEST

Page 41: Symfony2. Unit testing by Vadim Kharitonov

TESTS\TWIG\EXTENSION\FIXTURES\FILTERS\SQR.TEST

Page 42: Symfony2. Unit testing by Vadim Kharitonov

TWIG\EXTENSION\USEREXTENSION

Page 43: Symfony2. Unit testing by Vadim Kharitonov

TESTS\TWIG\EXTENSION\USEREXTENSIONTEST

Page 44: Symfony2. Unit testing by Vadim Kharitonov

3. CODE CHARACTERISTICSWhat percentage of the code coverage do u have?

Page 45: Symfony2. Unit testing by Vadim Kharitonov

3.1. CODE COVERAGE

Page 46: Symfony2. Unit testing by Vadim Kharitonov

$ bin/phpunit -c app --coverage-text

Page 47: Symfony2. Unit testing by Vadim Kharitonov

$ bin/phpunit -c app --coverage-

html=../report

Page 48: Symfony2. Unit testing by Vadim Kharitonov

3.2 PHP COPY/PASTEDETECTOR

$ wget https://phar.phpunit.de/phpcpd.phar

$ chmod +x phpcpd.phar

$ ./phpcpd.phar --exclude="*Test" src

Page 49: Symfony2. Unit testing by Vadim Kharitonov