-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
911fe50
commit b040878
Showing
7 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="false"> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Matters; | ||
|
||
class Armor | ||
{ | ||
private $defense; | ||
|
||
public function __construct($defense) | ||
{ | ||
$this->defense = $defense; | ||
} | ||
|
||
public function getDefense() | ||
{ | ||
return $this->defense; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Matters; | ||
|
||
class Character | ||
{ | ||
private $life; | ||
private $force; | ||
private $armor; | ||
private $weapon; | ||
|
||
public function __construct($life, $force) | ||
{ | ||
$this->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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Matters; | ||
|
||
class Weapon | ||
{ | ||
private $damages; | ||
|
||
public function __construct($damages) | ||
{ | ||
$this->damages = $damages; | ||
} | ||
|
||
public function getDamages() | ||
{ | ||
return $this->damages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Matters; | ||
|
||
use \PHPUnit\Framework\TestCase; | ||
|
||
class CharacterTest extends TestCase | ||
{ | ||
public function testAttack() { | ||
$hero = new Character(30, 5); | ||
$vilain = new Character(25, 8); | ||
|
||
$theBiggestSwordOfAllTime = new Weapon(50); | ||
$hero->equip($theBiggestSwordOfAllTime); | ||
|
||
$simpleHoodie = new Armor(1); | ||
$vilain->putsOn($simpleHoodie); | ||
|
||
$hero->attack($vilain); | ||
self::assertFalse($vilain->isAlive()); | ||
} | ||
} |