Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[+]: namespaces / tests / composer ...
- Loading branch information
Showing
4 changed files
with
104 additions
and
5 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 |
---|---|---|
@@ -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; | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
|
@@ -20,5 +20,11 @@ | |
}, | ||
"config": { | ||
"preferred-install": "dist" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MyApp\\": ["app/classes/"] | ||
} | ||
} | ||
|
||
} |
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,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()); | ||
} | ||
} |
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