Skip to content

Commit

Permalink
issue-X add phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
louiscelier committed Feb 17, 2018
1 parent 911fe50 commit b68a6c1
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 9 deletions.
25 changes: 18 additions & 7 deletions .travis.yml
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
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions phpunit.xml
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>
18 changes: 18 additions & 0 deletions src/Armor.php
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;
}
}
43 changes: 43 additions & 0 deletions src/Character.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Matters;

class Character
{
private $life;
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->receiveDamage($this->weapon->getDamages() + $this->force);
}

public function receiveDamage($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 $life > 0;
}
};
18 changes: 18 additions & 0 deletions src/Weapon.php
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;
}
}
22 changes: 22 additions & 0 deletions tests/CharacterTest.php
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());
}
}

0 comments on commit b68a6c1

Please sign in to comment.