Skip to content

Commit 1c41ff6

Browse files
committed
[+]: namespaces / tests / composer ...
1 parent f1f6b63 commit 1c41ff6

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php namespace MyApp\Helper;
2+
3+
/**
4+
* Created by PhpStorm.
5+
* User: menadwork-user
6+
* Date: 04.11.2014
7+
* Time: 01:32
8+
*/
9+
10+
class CalculateTicketPrice {
11+
protected $plan = array();
12+
protected $price = 0;
13+
14+
public function __construct()
15+
{
16+
$this->plan[1] = 5;
17+
$this->plan[2] = 10;
18+
$this->plan[3] = 12.5;
19+
$this->plan[4] = 17.5;
20+
}
21+
22+
/**
23+
* add ticket(s)
24+
*
25+
* @param int $planKey
26+
* @param int $number
27+
*/
28+
public function add($planKey = 0, $number = 1) {
29+
$this->price += ($this->plan[$planKey] * $number);
30+
}
31+
32+
/**
33+
* @return array
34+
*/
35+
public function getPlan()
36+
{
37+
return $this->plan;
38+
}
39+
40+
/**
41+
* @param array $plan
42+
*/
43+
public function setPlan($plan)
44+
{
45+
$this->plan = $plan;
46+
}
47+
48+
/**
49+
* @return int
50+
*/
51+
public function getPrice()
52+
{
53+
return $this->price;
54+
}
55+
56+
/**
57+
* @param int $price
58+
*/
59+
public function setPrice($price)
60+
{
61+
$this->price = $price;
62+
}
63+
64+
65+
}

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
},
2121
"config": {
2222
"preferred-install": "dist"
23+
},
24+
"autoload": {
25+
"psr-4": {
26+
"MyApp\\": ["app/classes/"]
27+
}
2328
}
29+
2430
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
use MyApp\Helper\CalculateTicketPrice;
3+
4+
/**
5+
* Created by PhpStorm.
6+
* User: menadwork-user
7+
* Date: 04.11.2014
8+
* Time: 01:40
9+
*/
10+
11+
class CalculateTicketPriceTest extends PHPUnit_Framework_TestCase {
12+
13+
/**
14+
* @var CalculateTicketPrice
15+
*/
16+
protected $calc;
17+
18+
public function __construct()
19+
{
20+
$this->calc = new CalculateTicketPrice();
21+
}
22+
23+
public function testAdd()
24+
{
25+
26+
$this->calc->add(1);
27+
$this->calc->add(2);
28+
29+
$this->assertEquals(15, $this->calc->getPrice());
30+
}
31+
}

test/configuration.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ To change this template file, choose Tools | Templates
55
and open the template in the editor.
66
-->
77

8-
<!-- see http://www.phpunit.de/wiki/Documentation -->
9-
<!--phpunit bootstrap="/path/to/bootstrap.php"
8+
<phpunit bootstrap="bootstrap.php"
109
colors="false"
1110
convertErrorsToExceptions="true"
1211
convertNoticesToExceptions="true"
1312
convertWarningsToExceptions="true"
1413
stopOnFailure="true">
15-
</phpunit-->
16-
17-
<phpunit colors="false"/>
14+
</phpunit>

0 commit comments

Comments
 (0)