Skip to content

Commit

Permalink
Updated test for JoinPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hirak committed Feb 6, 2016
1 parent b1e4e7b commit edfc5c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 78 deletions.
8 changes: 0 additions & 8 deletions src/Aspects/JoinPoint.php
Expand Up @@ -42,14 +42,6 @@ public function attach(SplObserver $observer)
$this->storage->attach($observer);
}

public function attachArray(array $observers)
{
$storage = $this->storage;
foreach ($observers as $observer) {
$storage->attach($observer);
}
}

public function detach(SplObserver $observer)
{
$this->storage->detach($observer);
Expand Down
78 changes: 8 additions & 70 deletions tests/unit/Aspects/JoinPointTest.php
@@ -1,81 +1,19 @@
<?php
namespace Hirak\Prestissimo\Aspects;

use Composer\IO;

class JoinPointTest extends \PHPUnit_Framework_TestCase
{
protected static $req;
protected $pre;

public static function setUpBeforeClass() {
self::$req = new HttpGetRequest(
'packagist.org',
'https://packagist.org/packages.json',
new \Composer\IO\NullIO
);
}

public function setUp()
{
$this->pre = new JoinPoint('pre-download', self::$req);
}

function testAttachArray()
{

self::assertAttributeEmpty('storage', $this->pre);
$this->pre->attachArray(array(
new AspectRedirect,
new AspectProxy,
)
);
self::assertAttributeNotEmpty('storage', $this->pre);
}

function testDetach()
{
self::assertAttributeEmpty('storage', $this->pre);
$observer = new AspectRedirect;
$this->pre->attach($observer);
self::assertAttributeNotEmpty('storage', $this->pre);
$this->pre->detach($observer);
self::assertAttributeEmpty('storage', $this->pre);
}

/**
* @covers Hirak\Prestissimo\Aspects\JoinPoint::refRequest
* @covers Hirak\Prestissimo\Aspects\JoinPoint::setRequest
* @covers Hirak\Prestissimo\Aspects\JoinPoint::refResponse
* @covers Hirak\Prestissimo\Aspects\JoinPoint::setResponse
* @covers Hirak\Prestissimo\Aspects\JoinPoint::notify
*/
function testSetRequest()
public function testConstruct()
{
$req = new HttpGetRequest(
'api.github.com',
'https://api.github.com/repos/brunoric/prestissimo/zipball/',
new \Composer\IO\NullIO
'example.com',
'https://example.com/',
new IO\NullIO
);
self::assertEquals($this->pre->refRequest()->origin, 'packagist.org');
self::assertEquals($this->pre->refRequest()->path, '/packages.json');

$this->pre->setRequest($req);
self::assertEquals($this->pre->refRequest()->origin, 'github.com');
self::assertEquals($this->pre->refRequest()->path, '/repos/brunoric/prestissimo/zipball/');

$observer = new AspectRedirect;
$this->pre->attach($observer);
$this->pre->notify();
self::assertEquals($this->pre->refRequest()->path, '/brunoric/prestissimo/legacy.zip/');


$res = new HttpGetResponse(
'errno',
'error',
array()
);
self::assertEmpty($this->pre->refResponse());
$this->pre->setResponse($res);
self::assertNotEmpty($this->pre->refResponse());
$joinPoint = new JoinPoint('pre-download', $req);
self::assertInstanceOf('Hirak\Prestissimo\Aspects\JoinPoint', $joinPoint);
}

}

0 comments on commit edfc5c2

Please sign in to comment.