Completed
Pull Request — master (#6066)
by Sam
12:53
created

CampaignAdminTest::testInvalidDataHandling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use SilverStripe\Dev\SapphireTest;
4
use SilverStripe\Admin\CampaignAdmin;
5
use SilverStripe\ORM\Versioning\ChangeSet;
6
use SilverStripe\ORM\UnexpectedDataException;
7
8
class CampaignAdminTest extends SapphireTest
9
{
10
11
	/**
12
	 * Call a protected method on an object via reflection
13
	 *
14
	 * @param object $object The object to call the method on
15
	 * @param string $method The name of the method
16
	 * @param array $args The arguments to pass to the method
17
	 */
18
	function callProtectedMethod($object, $method, $args = []) {
19
	  $class = new ReflectionClass(get_class($object));
20
	  $methodObj = $class->getMethod($method);
21
	  $methodObj->setAccessible(true);
22
	  return $methodObj->invokeArgs($object, $args);
23
	}
24
25
	function testInvalidDataHandling() {
26
		$changeset = new CampaignAdminTest_InvalidChangeSet();
27
		$admin = new CampaignAdmin();
28
29
		$result = $this->callProtectedMethod($admin, 'getChangeSetResource', [$changeset] );
30
		$this->assertEquals('Corrupt database! bad data' , $result['Description']);
31
	}
32
}
33
34
class CampaignAdminTest_InvalidChangeSet extends ChangeSet
35
{
36
	function sync()
37
	{
38
		throw new UnexpectedDataException("bad data");
39
	}
40
}
41