From ad85bb0444047c4e9d36ab64837cf4827cdab5cc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 20 Jun 2018 21:10:52 +0200 Subject: [PATCH] TASK: First example test and setup --- .gitignore | 5 +++ Classes/Controller/FrontendUserController.php | 38 ++++++++++++++++ Classes/Domain/Model/Address.php | 45 +++++++++++++++++++ composer.json | 25 +++++++++++ readme.rst | 45 +++++++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 .gitignore create mode 100644 Classes/Controller/FrontendUserController.php create mode 100644 Classes/Domain/Model/Address.php create mode 100644 composer.json create mode 100644 readme.rst diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93219f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +composer.lock +vendor +index.php +typo3 +Tests diff --git a/Classes/Controller/FrontendUserController.php b/Classes/Controller/FrontendUserController.php new file mode 100644 index 0000000..909fdf4 --- /dev/null +++ b/Classes/Controller/FrontendUserController.php @@ -0,0 +1,38 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use TYPO3\CMS\Extbase\Domain\Model\FrontendUser; +use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; + +/** + * Lists and enables editing of frontend users. + */ +class FrontendUserController extends ActionController +{ + /** + * @param FrontendUser $frontendUser + */ + public function showAction(FrontendUser $frontendUser) + { + $this->view->assign('frontendUser', $frontendUser); + } +} diff --git a/Classes/Domain/Model/Address.php b/Classes/Domain/Model/Address.php new file mode 100644 index 0000000..a585c02 --- /dev/null +++ b/Classes/Domain/Model/Address.php @@ -0,0 +1,45 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use TYPO3\CMS\Extbase\DomainObject\AbstractValueObject; + +class Address extends AbstractValueObject +{ + protected $street = ''; + protected $houseNumber = ''; + + public function __construct(string $street, string $houseNumber) + { + $this->street = trim($street); + $this->houseNumber = trim($houseNumber); + } + + public function getStreet() : string + { + return $this->street; + } + + public function getHouseNumber() : string + { + return $this->houseNumber; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fc4b5a3 --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "codappix/testing_talk", + "description": "Example Extension to show testing", + "type": "typo3-cms-extension", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Daniel Siepmann", + "email": "coding@daniel-siepmann.de" + } + ], + "autoload": { + "psr-4": { + "Codappix\\TestingTalk\\": "Classes/" + } + }, + "require": { + "typo3/cms-core": "^8.7" + }, + "extra": { + "typo3/cms": { + "web-dir": "web" + } + } +} diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..06b815a --- /dev/null +++ b/readme.rst @@ -0,0 +1,45 @@ +Testing Talk +============ + +Clean everything:: + + rm -rf composer.lock vendor web Tests + +Install dependencies +-------------------- + +Using composer:: + + composer install + +PHPUnit Installation +-------------------- + +Install phpunit:: + + composer require --dev phpunit/phpunit ^6.5 + +Why 6.x? We use 6.x to support PHP 7.0. + +Check installation:: + + ./vendor/bin/phpunit --version + +Links: + +* https://phpunit.de/ + +* https://packagist.org/packages/phpunit/phpunit + +Create first test +----------------- + +We want to test the controller first:: + + mkdir -p Tests/Unit/Domain/Model + cp Resources/Private/CodeExamples/Tests/Unit/Domain/Model/AddressTest.php \ + Tests/Unit/Domain/Model/AddressTest.php + +Execute first test:: + + ./vendor/bin/phpunit Tests/Unit/