WorkflowEmbargoExpiryTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 299
Duplicated Lines 40.47 %

Coupling/Cohesion

Components 0
Dependencies 8
Metric Value
wmc 11
lcom 0
cbo 8
dl 121
loc 299
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testFutureDatesJobs() 0 22 1
A setUp() 0 5 1
A __construct() 0 6 2
B testDesiredRemovesJobs() 0 30 1
B testPublishActionWithFutureDates() 0 29 1
A testPastPublishThenUnpublish() 49 49 1
A testPastUnPublishThenPublish() 49 49 1
B testPastPublishWithWorkflowInEffect() 0 44 1
A createDefinition() 23 23 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @author [email protected]
5
 * @license BSD License http://silverstripe.org/bsd-license/
6
 */
7
class WorkflowEmbargoExpiryTest extends SapphireTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
9
	public function setUp() {
10
		parent::setUp();
11
12
		SS_Datetime::set_mock_now('2014-01-05 12:00:00');
13
	}
14
15
	public function tearDown() {
16
		SS_Datetime::clear_mock_now();
17
		parent::tearDown();
18
	}
19
20
	/**
21
	 * @var array
22
	 */
23
	protected $requiredExtensions = array(
24
		'SiteTree' => array(
25
			'WorkflowEmbargoExpiryExtension',
26
			'Versioned',
27
		)
28
	);
29
30
	/**
31
	 * @var array
32
	 */
33
	protected $illegalExtensions = array(
34
		'SiteTree' => array(
35
			"Translatable",
36
		)
37
	);
38
39
	public function __construct() {
40
		if(!class_exists('AbstractQueuedJob')) {
41
			$this->skipTest = true;
42
		}
43
		parent::__construct();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class SapphireTest as the method __construct() does only exist in the following sub-classes of SapphireTest: FileFinderTest, ManifestFileFinderTest, MemberTest, WorkflowEmbargoExpiryTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
44
	}
45
46
	public function testFutureDatesJobs() {
47
		$page = new Page();
48
49
		$page->PublishOnDate = '2020-01-01 00:00:00';
50
		$page->UnPublishOnDate = '2020-01-01 01:00:00';
51
52
		// Two writes are necessary for this to work on new objects
53
		$page->write();
54
		$page->write();
55
56
		$this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
		$this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58
59
		// Check date ranges
60
		$now = strtotime(SS_Datetime::now()->getValue());
61
		$publish = strtotime($page->PublishJob()->StartAfter);
62
		$unPublish = strtotime($page->UnPublishJob()->StartAfter);
63
64
		$this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65
		$this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
		$this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
	}
68
69
	public function testDesiredRemovesJobs() {
70
		$page = new Page();
71
72
		$page->PublishOnDate = '2020-01-01 00:00:00';
73
		$page->UnPublishOnDate = '2020-01-01 01:00:00';
74
75
		// Two writes are necessary for this to work on new objects
76
		$page->write();
77
		$page->write();
78
79
		$this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
		$this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
82
		// Check date ranges
83
		$now = strtotime(SS_Datetime::now()->getValue());
84
		$publish = strtotime($page->PublishJob()->StartAfter);
85
		$unPublish = strtotime($page->UnPublishJob()->StartAfter);
86
87
		$this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
		$this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
		$this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
91
		$page->DesiredPublishDate = '2020-02-01 00:00:00';
92
		$page->DesiredUnPublishDate = '2020-02-01 02:00:00';
93
94
		$page->write();
95
96
		$this->assertTrue($page->PublishJobID == 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
		$this->assertTrue($page->UnPublishJobID == 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
98
	}
99
100
	public function testPublishActionWithFutureDates() {
101
		$action = new PublishItemWorkflowAction();
102
		$instance = new WorkflowInstance();
103
104
		$page = new Page();
105
		$page->Title = 'stuff';
106
		$page->DesiredPublishDate = '2020-02-01 00:00:00';
107
		$page->DesiredUnPublishDate = '2020-02-01 02:00:00';
108
109
		$page->write();
110
111
		$instance->TargetClass = $page->ClassName;
0 ignored issues
show
Documentation introduced by
The property TargetClass does not exist on object<WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
112
		$instance->TargetID = $page->ID;
0 ignored issues
show
Documentation introduced by
The property TargetID does not exist on object<WorkflowInstance>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
113
114
		$action->execute($instance);
115
116
		$page = DataObject::get_by_id('Page', $page->ID);
117
		$this->assertTrue($page->PublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
118
		$this->assertTrue($page->UnPublishJobID > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
120
		// Check date ranges
121
		$now = strtotime(SS_Datetime::now()->getValue());
122
		$publish = strtotime($page->PublishJob()->StartAfter);
123
		$unPublish = strtotime($page->UnPublishJob()->StartAfter);
124
125
		$this->assertGreaterThan($now, $publish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
		$this->assertGreaterThan($now, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
		$this->assertGreaterThan($publish, $unPublish);
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
128
	}
129
130
	/**
131
	 * Test that a page with a past publish date creates the correct jobs
132
	 */
133 View Code Duplication
	public function testPastPublishThenUnpublish() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
		$page = new Page();
135
		$page->Title = 'My Page';
136
		$page->write();
137
138
		// No publish
139
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
140
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
141
142
		// Set a past publish date
143
		$page->PublishOnDate = '2010-01-01 00:00:00';
144
		$page->write();
145
146
		// We should still have a job to publish this page, but not unpublish
147
		$this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
149
150
		// Check that this job is set for immediate run
151
		$publish = strtotime($page->PublishJob()->StartAfter);
152
		$this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
153
154
		// Now add an expiry date in the past, but after the current publish job,
155
		// and ensure that this correctly overrides the open publish request
156
		$page->UnPublishOnDate = '2010-01-02 00:00:00';
157
		$page->write();
158
159
		// Now we should have an unpublish job, but the publish job is noticably absent
160
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
161
		$this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
162
163
		// Check that this unpublish job is set for immediate run
164
		$unpublish = strtotime($page->UnPublishJob()->StartAfter);
165
		$this->assertEmpty($unpublish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
166
167
		// Now add an expiry date in the future, and ensure that we get the correct combination of
168
		// publish and unpublish jobs
169
		$page->UnPublishOnDate = '2015-01-01 12:00:00';
170
		$page->write();
171
172
		// Both jobs exist
173
		$this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
174
		$this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
175
176
		// Check that this unpublish job is set for immediate run and the unpublish for future
177
		$publish = strtotime($page->PublishJob()->StartAfter);
178
		$unpublish = strtotime($page->UnPublishJob()->StartAfter);
179
		$this->assertEmpty($publish); // for immediate run
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
180
		$this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $unpublish); // for later run
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
	}
182
183
	/**
184
	 * Test that a page with a past unpublish date creates the correct jobs
185
	 */
186 View Code Duplication
	public function testPastUnPublishThenPublish() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
		$page = new Page();
188
		$page->Title = 'My Page';
189
		$page->write();
190
191
		// No publish
192
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
193
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
194
195
		// Set a past unpublish date
196
		$page->UnPublishOnDate = '2010-01-01 00:00:00';
197
		$page->write();
198
199
		// We should still have a job to unpublish this page, but not publish
200
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
201
		$this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
202
203
		// Check that this job is set for immediate run
204
		$unpublish = strtotime($page->UnPublishJob()->StartAfter);
205
		$this->assertEmpty($unpublish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
206
207
		// Now add an publish date in the past, but after the unpublish job,
208
		// and ensure that this correctly overrides the open unpublish request
209
		$page->PublishOnDate = '2010-01-02 00:00:00';
210
		$page->write();
211
212
		// Now we should have an publish job, but the unpublish job is noticably absent
213
		$this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
214
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
215
216
		// Check that this publish job is set for immediate run
217
		$publish = strtotime($page->PublishJob()->StartAfter);
218
		$this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
219
220
		// Now add a publish date in the future, and ensure that we get the correct combination of
221
		// publish and unpublish jobs
222
		$page->PublishOnDate = '2015-01-01 12:00:00';
223
		$page->write();
224
225
		// Both jobs exist
226
		$this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
227
		$this->assertNotEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
228
229
		// Check that this unpublish job is set for immediate run and the unpublish for future
230
		$publish = strtotime($page->PublishJob()->StartAfter);
231
		$unpublish = strtotime($page->UnPublishJob()->StartAfter);
232
		$this->assertEmpty($unpublish); // for immediate run
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
233
		$this->assertGreaterThan(strtotime(SS_Datetime::now()->getValue()), $publish); // for later run
0 ignored issues
show
Bug introduced by
The method assertGreaterThan() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
234
	}
235
236
	public function testPastPublishWithWorkflowInEffect() {
237
		$definition = $this->createDefinition();
238
239
		$page = new Page();
240
		$page->Title = 'My page';
241
		$page->WorkflowDefinitionID = $definition->ID;
242
		$page->write();
243
244
		// No publish
245
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
246
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
247
248
		// Set a past publish date
249
		$page->DesiredPublishDate = '2010-01-01 00:00:00';
250
		$page->write();
251
252
		// Workflow is in effect. No jobs have been created yet as it's not approved.
253
		$this->assertEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
254
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
255
256
		// Advance the workflow so we can see what happens
257
		$instance = new WorkflowInstance();
258
		$instance->beginWorkflow($definition, $page);
259
		$instance->execute();
260
261
		// execute the "publish" workflow action
262
		$action = new PublishItemWorkflowAction();
263
		$action->execute($instance);
264
265
		// re-fetch the Page again.
266
		$page = Page::get()->byId($page->ID);
267
268
		// We now have a PublishOnDate field set
269
		$this->assertEquals('2010-01-01 00:00:00', $page->PublishOnDate);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
270
		$this->assertEmpty($page->DesiredPublishDate);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
271
272
		// Publish job has been setup
273
		$this->assertNotEmpty($page->PublishJobID);
0 ignored issues
show
Bug introduced by
The method assertNotEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
274
		$this->assertEmpty($page->UnPublishJobID);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
275
276
		// Check that this publish job is set for immediate run
277
		$publish = strtotime($page->PublishJob()->StartAfter);
278
		$this->assertEmpty($publish);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<WorkflowEmbargoExpiryTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
279
	}
280
281 View Code Duplication
	protected function createDefinition() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
282
		$definition = new WorkflowDefinition();
283
		$definition->Title = 'Dummy Workflow Definition';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowDefinition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
284
		$definition->write();
285
286
		$stepOne = new WorkflowAction();
287
		$stepOne->Title = 'Step One';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
288
		$stepOne->WorkflowDefID = $definition->ID;
0 ignored issues
show
Documentation introduced by
The property WorkflowDefID does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
289
		$stepOne->write();
290
291
		$stepTwo = new WorkflowAction();
292
		$stepTwo->Title = 'Step Two';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
293
		$stepTwo->WorkflowDefID = $definition->ID;
0 ignored issues
show
Documentation introduced by
The property WorkflowDefID does not exist on object<WorkflowAction>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
294
		$stepTwo->write();
295
296
		$transitionOne = new WorkflowTransition();
297
		$transitionOne->Title = 'Step One T1';
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
298
		$transitionOne->ActionID = $stepOne->ID;
0 ignored issues
show
Documentation introduced by
The property ActionID does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
299
		$transitionOne->NextActionID = $stepTwo->ID;
0 ignored issues
show
Documentation introduced by
The property NextActionID does not exist on object<WorkflowTransition>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
300
		$transitionOne->write();
301
302
		return $definition;
303
	}
304
305
}
306