Skip to content

Commit

Permalink
[+]: namespaces / tests / composer ...
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Nov 4, 2014
1 parent f1f6b63 commit 1c41ff6
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
65 changes: 65 additions & 0 deletions app/classes/Helper/CalculateTicketPrice.php
@@ -0,0 +1,65 @@
<?php namespace MyApp\Helper;

/**
* Created by PhpStorm.
* User: menadwork-user
* Date: 04.11.2014
* Time: 01:32
*/

class CalculateTicketPrice {
protected $plan = array();
protected $price = 0;

public function __construct()
{
$this->plan[1] = 5;
$this->plan[2] = 10;
$this->plan[3] = 12.5;
$this->plan[4] = 17.5;
}

/**
* add ticket(s)
*
* @param int $planKey
* @param int $number
*/
public function add($planKey = 0, $number = 1) {
$this->price += ($this->plan[$planKey] * $number);
}

/**
* @return array
*/
public function getPlan()
{
return $this->plan;
}

/**
* @param array $plan
*/
public function setPlan($plan)
{
$this->plan = $plan;
}

/**
* @return int
*/
public function getPrice()
{
return $this->price;
}

/**
* @param int $price
*/
public function setPrice($price)
{
$this->price = $price;
}


}
6 changes: 6 additions & 0 deletions composer.json
Expand Up @@ -20,5 +20,11 @@
},
"config": {
"preferred-install": "dist"
},
"autoload": {
"psr-4": {
"MyApp\\": ["app/classes/"]
}
}

}
31 changes: 31 additions & 0 deletions test/classes/CalculateTicketPriceTest.php
@@ -0,0 +1,31 @@
<?php
use MyApp\Helper\CalculateTicketPrice;

/**
* Created by PhpStorm.
* User: menadwork-user
* Date: 04.11.2014
* Time: 01:40
*/

class CalculateTicketPriceTest extends PHPUnit_Framework_TestCase {

/**
* @var CalculateTicketPrice
*/
protected $calc;

public function __construct()
{
$this->calc = new CalculateTicketPrice();
}

public function testAdd()
{

$this->calc->add(1);
$this->calc->add(2);

$this->assertEquals(15, $this->calc->getPrice());
}
}
7 changes: 2 additions & 5 deletions test/configuration.xml
Expand Up @@ -5,13 +5,10 @@ To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<!-- see http://www.phpunit.de/wiki/Documentation -->
<!--phpunit bootstrap="/path/to/bootstrap.php"
<phpunit bootstrap="bootstrap.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true">
</phpunit-->

<phpunit colors="false"/>
</phpunit>

0 comments on commit 1c41ff6

Please sign in to comment.