Skip to content

Commit

Permalink
Merge branch 'release/1.2.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkyle committed Aug 25, 2014
2 parents 3b18136 + 4b0666f commit d7adb06
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,8 @@
#Changelog

####v.1.2.6 / 25.08.2014
####v.1.2.6 to 1.2.7 / 25.08.2014
- Travis CI configuration: `before_script` becomes `install` – cf. [http://till.klampaeckel.de/blog/archives/204-Whats-wrong-with-composer-and-your-.travis.yml.html](http://till.klampaeckel.de/blog/archives/204-Whats-wrong-with-composer-and-your-.travis.yml.html)
- Implemented more tests; reaching 100% coverage

####v1.2.3 to 1.2.5 / 24.08.2014
- Added badges for Travis CI, Scrutinizer, Coveralls
Expand Down
6 changes: 3 additions & 3 deletions src/SourceAbstract.php
Expand Up @@ -25,9 +25,9 @@ public function getType()
public function jsonSerialize()
{
$result = new \StdClass;
$result->media = $this->getMedia();
$result->src = $this->getSrcset();
$result->type = $this->getType();
$result->media = $this->getMedia();
$result->srcset = $this->getSrcset();
$result->type = $this->getType();
return $result;
}
}
44 changes: 42 additions & 2 deletions tests/src/ResponsivePictureTest.php
Expand Up @@ -3,16 +3,56 @@

use \tomkyle\ResponsivePicture\MinWidthSource;
use \tomkyle\ResponsivePicture\ResponsivePicture;
use \tomkyle\ResponsivePicture\SourceInterface;

class ResponsivePictureTest extends \PHPUnit_Framework_TestCase {

public $object;

public function setUp()
{
$this->object = new ResponsivePicture( '//placehold.it/300x300', "Sample image");
}

public function testSimpleInstantiation( )
{
$pic = new ResponsivePicture( '//placehold.it/300x300', "Sample image");
$this->assertInstanceOf('\tomkyle\ResponsivePicture\ResponsivePicture', $this->object);
}

$this->assertInstanceOf('\tomkyle\ResponsivePicture\ResponsivePicture', $pic);
/**
* @dataProvider provideSomeSourceInterfaceMocks
*/
public function testAddingSource( $source_mock)
{
$this->object->add( $source_mock );
$this->assertSame( $source_mock, array_pop($this->object->sources) );
}

public function testGetIterator( )
{
$this->object->sources = [];
$this->object->add( $this->newSourceInterfaceMock() );
$this->object->add( $this->newSourceInterfaceMock() );
$this->object->add( $this->newSourceInterfaceMock() );

$iterator = $this->object->getIterator();

$this->assertInstanceOf('\ArrayIterator', $iterator);
$this->assertEquals(3, $iterator->count());
}

public function newSourceInterfaceMock()
{
return $this->getMock( '\tomkyle\ResponsivePicture\SourceInterface' );
}

public function provideSomeSourceInterfaceMocks()
{
return array(
array( $this->newSourceInterfaceMock() ),
array( $this->newSourceInterfaceMock() ),
array( $this->newSourceInterfaceMock() )
);
}

}
51 changes: 49 additions & 2 deletions tests/src/ResponsivePictureViewTest.php
Expand Up @@ -10,6 +10,8 @@ class ResponsivePictureViewTest extends \PHPUnit_Framework_TestCase {

/**
* @dataProvider provideResponsivePictureViewCtorParams
*
* @covers \tomkyle\ResponsivePicture\ResponsivePictureView::__construct
*/
public function testDefaultInstantiation( ResponsivePictureInterface $rp )
{
Expand All @@ -20,6 +22,8 @@ public function testDefaultInstantiation( ResponsivePictureInterface $rp )

/**
* @dataProvider provideResponsivePictureViewCtorParams
*
* @covers \tomkyle\ResponsivePicture\ResponsivePictureView::__construct
*/
public function testNoParamsInstantiation( ResponsivePictureInterface $rp )
{
Expand All @@ -30,11 +34,16 @@ public function testNoParamsInstantiation( ResponsivePictureInterface $rp )

/**
* @dataProvider provideResponsivePictureViewCtorParams
*
* @covers \tomkyle\ResponsivePicture\ResponsivePictureView::setPicture
*/
public function testFluentInterface( $rp )
public function testSetPicture( $rp )
{
$view = new ResponsivePictureView( $rp );
$this->assertInstanceOf('\tomkyle\ResponsivePicture\ResponsivePictureView', $view->setPicture( $rp ));

$result = $view->setPicture( $rp );
$this->assertTrue( $rp === $view->picture);
$this->assertInstanceOf('\tomkyle\ResponsivePicture\ResponsivePictureView', $result);
}


Expand All @@ -47,12 +56,37 @@ public function testIfValid( $rp )
$this->assertTrue( $view->valid() );
}


public function testIfNotValid( )
{
$view = new ResponsivePictureView;
$this->assertFalse( $view->valid() );
}

/**
* @dataProvider provideVariousCtorParamsForStringOutputTesting
*
* @covers \tomkyle\ResponsivePicture\ResponsivePictureView::__toString
*/
public function testToString( $picture = null, $template = null)
{
$view = new ResponsivePictureView($picture, $template);
$str = $view->__toString();
$this->assertTrue( is_string( $str ));
}


/**
* @covers \tomkyle\ResponsivePicture\ResponsivePictureView::__invoke
*/
public function testInvoke( $picture = null, $template = null)
{
$view = new ResponsivePictureView;

$str = $view( new ResponsivePicture( '//placehold.it/300x300', "Sample image") );
$this->assertTrue( is_string( $str ));
}



public function provideResponsivePictureViewCtorParams()
Expand All @@ -64,4 +98,17 @@ public function provideResponsivePictureViewCtorParams()




public function provideVariousCtorParamsForStringOutputTesting()
{
return array(
array( new ResponsivePicture( '//placehold.it/300x300', "Sample image"), __DIR__ . '/../../templates/responsivepicture.tpl.php' ),
array( new ResponsivePicture( '//placehold.it/300x300', "Sample image"), null),
array()
);
}




}
53 changes: 53 additions & 0 deletions tests/src/SourceAbstractTest.php
@@ -0,0 +1,53 @@
<?php
namespace tests;

use \tomkyle\ResponsivePicture\SourceAbstract;

class SourceAbstractTest extends \PHPUnit_Framework_TestCase {

public $class = '\tomkyle\ResponsivePicture\SourceAbstract';
public $stub;

public function setUp()
{
$this->stub = $this->getMockForAbstractClass( $this->class );
}


/**
* @dataProvider provideVariousKindOfArguments
*/
public function testGetSrcset( $any )
{
$this->stub->srcset = $any;
$this->assertEquals( $any, $this->stub->getSrcset() );
}

/**
* @dataProvider provideVariousKindOfArguments
*/
public function testGetMedia( $any )
{
$this->stub->media = $any;
$this->assertEquals( $any, $this->stub->getMedia() );
}

/**
* @dataProvider provideVariousKindOfArguments
*/
public function testGetType( $any )
{
$this->stub->type = $any;
$this->assertEquals( $any, $this->stub->getType() );
}

public function provideVariousKindOfArguments()
{
return array(
array( '(min-width: 1200px)' ),
array( null ),
array( 123 )
);
}

}
92 changes: 92 additions & 0 deletions tests/src/SourceTest.php
@@ -0,0 +1,92 @@
<?php
namespace tests;

use \tomkyle\ResponsivePicture\Source;

class SourceTest extends \PHPUnit_Framework_TestCase {

/**
* @dataProvider provideVariousCtorParams
*
* @covers \tomkyle\ResponsivePicture\Source::__construct
*/
public function testDefaultInstantiation( $media, $srcset)
{
$source = new Source( $media, $srcset);
$this->assertInstanceOf('\tomkyle\ResponsivePicture\Source', $source);
$this->assertEquals( $source->media, $media );
$this->assertEquals( $source->srcset, $srcset );
}


/**
* @dataProvider provideVariousCtorParamsWithGivenType
*
* @covers \tomkyle\ResponsivePicture\Source::__construct
*/
public function testInstantiationWithGivenType( $media, $srcset, $type )
{
$source = new Source( $media, $srcset, $type);
$this->assertInstanceOf('\tomkyle\ResponsivePicture\Source', $source);
$this->assertEquals( $source->media, $media );
$this->assertEquals( $source->srcset, $srcset );
$this->assertEquals( $source->type, $type );
}

/**
* @dataProvider provideVariousCtorParamsWithGivenType
*
* @covers \tomkyle\ResponsivePicture\Source::getMedia
* @covers \tomkyle\ResponsivePicture\Source::getSrcset
* @covers \tomkyle\ResponsivePicture\Source::getType
*/
public function testGetterInterceptors( $media, $srcset, $type )
{
$source = new Source( $media, $srcset, $type);
$this->assertInstanceOf('\tomkyle\ResponsivePicture\Source', $source);
$this->assertEquals( $source->getMedia(), $media );
$this->assertEquals( $source->getSrcset(), $srcset );
$this->assertEquals( $source->getType(), $type );
}




/**
* @dataProvider provideVariousCtorParamsWithGivenType
*
* @covers \tomkyle\ResponsivePicture\Source::jsonSerialize
*/
public function testJsonExport( $media, $srcset, $type )
{
$source = new Source( $media, $srcset, $type);

$json_source = json_encode( $source );
$decoded_json_source = json_decode( $json_source );

$this->assertInstanceOf('\StdClass', $decoded_json_source);
$this->assertEquals( $decoded_json_source->media, $media );
$this->assertEquals( $decoded_json_source->srcset, $srcset );
$this->assertEquals( $decoded_json_source->type, $type );
}



public function provideVariousCtorParams()
{
return array(
array('(min-width: 1200px)', '//placehold.it/1200x1200'),
array('(min-width: 800px)', '//placehold.it/800x600'),
array('(min-width: 480px)', '//placehold.it/480x200')
);
}

public function provideVariousCtorParamsWithGivenType()
{
return array(
array('(min-width: 1200px)', '//placehold.it/1200x1200', 'image/webp'),
array('(min-width: 800px)', '//placehold.it/800x600', 'image/webp'),
array('(min-width: 480px)', '//placehold.it/480x200', 'image/webp')
);
}
}

0 comments on commit d7adb06

Please sign in to comment.