Skip to content

Commit 1dc81b5

Browse files
author
Changwan Jun
committed
add ppt and sample files of May, 2015 first presentation.
1 parent 2031dd1 commit 1dc81b5

File tree

8 files changed

+187
-0
lines changed

8 files changed

+187
-0
lines changed
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "wani/pug-150502-ppt",
3+
"authors": [
4+
{
5+
"name": "Changwan Jun",
6+
"email": "[email protected]"
7+
}
8+
],
9+
"autoload": {
10+
"psr-4": {
11+
"Wandu\\PugSample\\": "src/"
12+
}
13+
},
14+
"autoload-dev": {
15+
"psr-4": {
16+
"Wandu\\PugSample\\": "tests/"
17+
}
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "4.5.*",
21+
"mockery/mockery": "0.9.*"
22+
}
23+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
require __DIR__ .'/vendor/autoload.php';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<phpunit backupGlobals="false"
2+
backupStaticAttributes="false"
3+
bootstrap="./phpunit.php"
4+
processIsolation="false"
5+
syntaxCheck="false"
6+
stopOnFailure="false"
7+
colors="true"
8+
>
9+
<testsuites>
10+
<testsuite name="Pug150502 Samples Suites">
11+
<directory>./tests/</directory>
12+
</testsuite>
13+
</testsuites>
14+
</phpunit>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace Wandu\PugSample;
3+
4+
class Customer
5+
{
6+
/** @var string */
7+
private $name;
8+
9+
/**
10+
* @param string $name
11+
*/
12+
public function __construct($name)
13+
{
14+
$this->name = $name;
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getName()
21+
{
22+
return ucfirst($this->name);
23+
}
24+
}
25+
26+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
namespace Wandu\PugSample;
3+
4+
use Closure;
5+
6+
class Greeter
7+
{
8+
/** @var Customer */
9+
private $customer;
10+
11+
/**
12+
* @param Customer $customer
13+
*/
14+
public function __construct(Customer $customer)
15+
{
16+
$this->customer = $customer;
17+
}
18+
19+
/**
20+
* @return string
21+
*/
22+
public function sayHelloPublic()
23+
{
24+
return "Hello, {$this->customer->getName()}! (public)";
25+
}
26+
27+
/**
28+
* @return string
29+
*/
30+
private function sayHelloPrivate()
31+
{
32+
return "Hello, {$this->customer->getName()}! (private)";
33+
}
34+
35+
/**
36+
* @param callable $handler
37+
* @return mixed
38+
*/
39+
public function doSomethingWithCustomer(Closure $handler)
40+
{
41+
return $handler->__invoke($this->customer);
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Wandu\PugSample;
3+
4+
class Dummy
5+
{
6+
public function handler()
7+
{}
8+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace Wandu\PugSample;
3+
4+
use PHPUnit_Framework_TestCase;
5+
use Mockery;
6+
use ReflectionClass;
7+
use Closure;
8+
9+
class GreeterTest extends PHPUnit_Framework_TestCase
10+
{
11+
public function tearDown()
12+
{
13+
Mockery::close();
14+
}
15+
16+
public function testSayHelloPublic()
17+
{
18+
$mockCustomer = Mockery::mock(Customer::class);
19+
$mockCustomer->shouldReceive('getName')->andReturn('Changwan');
20+
21+
$greeter = new Greeter($mockCustomer);
22+
23+
$this->assertAttributeInstanceOf(Customer::class, 'customer', $greeter);
24+
$this->assertAttributeEquals($mockCustomer, 'customer', $greeter);
25+
26+
$this->assertEquals('Hello, Changwan! (public)', $greeter->sayHelloPublic());
27+
}
28+
29+
public function testSayHelloPrivate()
30+
{
31+
$mockCustomer = Mockery::mock(Customer::class);
32+
$mockCustomer->shouldReceive('getName')->andReturn('Wandu');
33+
34+
$greeter = new Greeter($mockCustomer);
35+
36+
$classReflection = new ReflectionClass(Greeter::class);
37+
$sayHelloPrivateMethod = $classReflection->getMethod('sayHelloPrivate')->getClosure($greeter);
38+
39+
$this->assertInstanceOf(Closure::class, $sayHelloPrivateMethod);
40+
$this->assertEquals('Hello, Wandu! (private)', $sayHelloPrivateMethod->__invoke());
41+
}
42+
43+
public function testDoSomethingSimple()
44+
{
45+
$mockCustomer = Mockery::mock(Customer::class);
46+
$mockCustomer->shouldReceive('getName')->andReturn('Wandu');
47+
48+
$greeter = new Greeter($mockCustomer);
49+
50+
$this->assertEquals(30, $greeter->doSomethingWithCustomer(function ($param1) use ($mockCustomer) {
51+
$this->assertSame($mockCustomer, $param1);
52+
return 30;
53+
}));
54+
}
55+
56+
public function testDoSomethingWithDummy()
57+
{
58+
$mockCustomer = Mockery::mock(Customer::class);
59+
$mockCustomer->shouldReceive('getName')->andReturn('Wandu');
60+
61+
$mockHandler = Mockery::mock(Dummy::class);
62+
$mockHandler->shouldReceive('handler')->once()->with($mockCustomer)->andReturn(30);
63+
64+
$greeter = new Greeter($mockCustomer);
65+
66+
$classReflection = new ReflectionClass(get_class($mockHandler));
67+
$handler = $classReflection->getMethod('handler')->getClosure($mockHandler);
68+
69+
$this->assertEquals(30, $greeter->doSomethingWithCustomer($handler));
70+
}
71+
}

0 commit comments

Comments
 (0)