From b0408789c01908b816600ea39b1654c01dd0a0f0 Mon Sep 17 00:00:00 2001 From: Louis Celier Date: Fri, 16 Feb 2018 22:56:55 +0100 Subject: [PATCH] issue-X add phpunit --- .travis.yml | 25 ++++++++++++++++------- composer.json | 10 ++++++++-- phpunit.xml | 11 +++++++++++ src/Armor.php | 18 +++++++++++++++++ src/Character.php | 44 +++++++++++++++++++++++++++++++++++++++++ src/Weapon.php | 18 +++++++++++++++++ tests/CharacterTest.php | 22 +++++++++++++++++++++ 7 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 phpunit.xml create mode 100644 src/Armor.php create mode 100644 src/Character.php create mode 100644 src/Weapon.php create mode 100644 tests/CharacterTest.php diff --git a/.travis.yml b/.travis.yml index d2d664c..2b7bbf3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,23 @@ -dist: trusty +language: php -services: - - docker +php: + - '7.1' + - '7.2' install: - - cp .env.example .env - - eval "$(ssh-agent -s)" - - docker-compose up -d + - composer install script: - - curl localhost:8080 + - vendor/bin/phpunit --bootstrap vendor/autoload.php tests + +jobs: + include: + - stage: build + services: + - docker + install: + - cp .env.example .env + - eval "$(ssh-agent -s)" + - docker-compose up -d + script: + - curl localhost:8080 diff --git a/composer.json b/composer.json index 077c7a1..9bfc584 100644 --- a/composer.json +++ b/composer.json @@ -3,9 +3,15 @@ "description": "This app is an example application for using docker as a dev environment", "type": "project", "require-dev": { - "phpro/grumphp": "^0.13.1", "friendsofphp/php-cs-fixer": "^2.10", - "jakub-onderka/php-parallel-lint": "^0.9.2" + "jakub-onderka/php-parallel-lint": "^0.9.2", + "phpro/grumphp": "^0.13.1", + "phpunit/phpunit": "^7.0" + }, + "autoload": { + "psr-4": { + "Matters\\": "src/" + } }, "license": "MIT", "authors": [ diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..9c90a5b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,11 @@ + + + diff --git a/src/Armor.php b/src/Armor.php new file mode 100644 index 0000000..dfbcd52 --- /dev/null +++ b/src/Armor.php @@ -0,0 +1,18 @@ +defense = $defense; + } + + public function getDefense() + { + return $this->defense; + } +} diff --git a/src/Character.php b/src/Character.php new file mode 100644 index 0000000..0109bac --- /dev/null +++ b/src/Character.php @@ -0,0 +1,44 @@ +life = $life; + $this->force = $force; + $this->weapon = new Weapon(0); + $this->armor = new Armor(0); + } + + public function attack(Character $opponent) + { + $opponent->receiveDamages($this->weapon->getDamages() + $this->force); + } + + public function receiveDamages($damages) + { + $this->life -= $damages - ($this->armor->getDefense() + $this->force); + } + + public function equip(Weapon $weapon) + { + $this->weapon = $weapon; + } + + public function putsOn(Armor $armor) + { + $this->armor = $armor; + } + + public function isAlive() + { + return $this->life > 0; + } +}; diff --git a/src/Weapon.php b/src/Weapon.php new file mode 100644 index 0000000..ccc0f1b --- /dev/null +++ b/src/Weapon.php @@ -0,0 +1,18 @@ +damages = $damages; + } + + public function getDamages() + { + return $this->damages; + } +} diff --git a/tests/CharacterTest.php b/tests/CharacterTest.php new file mode 100644 index 0000000..4caaadd --- /dev/null +++ b/tests/CharacterTest.php @@ -0,0 +1,22 @@ +equip($theBiggestSwordOfAllTime); + + $simpleHoodie = new Armor(1); + $vilain->putsOn($simpleHoodie); + + $hero->attack($vilain); + self::assertFalse($vilain->isAlive()); + } +}