Skip to content

Commit

Permalink
NEW Remove Mockery from phpunit test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Feb 5, 2018
1 parent fe7550a commit 9499d19
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 64 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"mockery/mockery": "^0.9",
"squizlabs/php_codesniffer": "^3.0",
"silverstripe/reports": "^4.0",
"silverstripe/siteconfig": "^4.0"
Expand Down
27 changes: 7 additions & 20 deletions tests/SegmentFieldModifier/IDSegmentFieldModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,13 @@

namespace SilverStripe\Forms\Tests;

use Mockery;
use stdClass;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\SegmentFieldModifier\IDSegmentFieldModifier;

/**
* @cover IDSegmentFieldModifier
*/
class IDSegmentFieldModifierTest extends SapphireTest
{
/**
* @inheritdoc
*/
protected function tearDown()
{
Mockery::close();

parent::tearDown();
}

/**
* @test
*/
public function testGetPreview()
{
$modifier = new IDSegmentFieldModifier();
Expand All @@ -43,11 +26,15 @@ public function testGetPreview()
*/
protected function getNewFormMock()
{
$record = new StdClass();
$mock = $this->getMockBuilder(Form::class)
->disableOriginalConstructor()
->setMethods(['getRecord'])
->getMock();

$record = new stdClass();
$record->ID = 123;

$mock = Mockery::mock(Form::class);
$mock->shouldReceive('getRecord')->andReturn($record);
$mock->method('getRecord')->willReturn($record);

return $mock;
}
Expand Down
23 changes: 3 additions & 20 deletions tests/SegmentFieldModifier/SlugSegmentFieldModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,12 @@

namespace SilverStripe\Forms\Tests;

use Mockery;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;

/**
* @cover SlugSegmentFieldModifier
*/
class SlugSegmentFieldModifierTest extends SapphireTest
{
/**
* @inheritdoc
*/
protected function tearDown()
{
Mockery::close();

parent::tearDown();
}

/**
* @test
*/
public function testGetPreview()
{
$modifier = new SlugSegmentFieldModifier();
Expand All @@ -41,12 +24,12 @@ public function testGetPreview()
}

/**
* @return Form
* @return HTTPRequest
*/
protected function getNewRequestMock()
{
$mock = Mockery::mock(HTTPRequest::class);
$mock->shouldReceive('getVar')->with('value')->andReturn('This is a LONG value!');
$mock = new HTTPRequest('GET', '/');
$mock->offsetSet('value', 'This is a LONG value!');

return $mock;
}
Expand Down
28 changes: 5 additions & 23 deletions tests/SegmentFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,14 @@

namespace SilverStripe\Forms\Tests;

use Mockery;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\SegmentField;
use SilverStripe\Forms\SegmentFieldModifier\AbstractSegmentFieldModifier;

/**
* @cover SegmentField
* @cover AbstractSegmentFieldModifier
*/
class SegmentFieldTest extends SapphireTest
{
/**
* @inheritdoc
*/
protected function tearDown()
{
Mockery::close();

parent::tearDown();
}

/**
* @test
*/
public function testSuggest()
{
$field = new SegmentField('Example');
Expand All @@ -44,9 +26,6 @@ public function testSuggest()
$this->assertEquals('array-preview', $decoded->preview);
}

/**
* @test
*/
public function testGettersAndSetters()
{
$field = new SegmentField('Example');
Expand Down Expand Up @@ -75,14 +54,17 @@ public function testGettersAndSetters()
*/
protected function getNewRequestMock()
{
return Mockery::mock(HTTPRequest::class);
return new HTTPRequest('GET', '/');
}

/**
* @return Form
*/
protected function getNewFormMock()
{
return Mockery::mock(Form::class);
return $this->getMockBuilder(Form::class)
->disableOriginalConstructor()
->setMethods(null)
->getMock();
}
}

0 comments on commit 9499d19

Please sign in to comment.