1 | <?php |
||
27 | class VersionsCheckPluginTest extends \PHPUnit_Framework_TestCase |
||
28 | { |
||
29 | /** |
||
30 | * @var BufferIO |
||
31 | */ |
||
32 | private $io; |
||
33 | |||
34 | /** |
||
35 | * @var Composer|\PHPUnit_Framework_MockObject_MockObject |
||
36 | */ |
||
37 | private $composer; |
||
38 | |||
39 | /** |
||
40 | * @var Config |
||
41 | */ |
||
42 | private $config; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | protected function setUp() |
||
48 | { |
||
49 | $this->io = new BufferIO(); |
||
50 | $this->composer = $this->getMock('Composer\Composer'); |
||
51 | $this->config = new Config(false); |
||
52 | |||
53 | $this->composer->expects($this->any())->method('getConfig') |
||
54 | ->willReturn($this->config); |
||
55 | $this->composer->expects($this->any())->method('getPackage') |
||
56 | ->willReturn(new RootPackage('my/project', '1.0.0', '1.0.0')); |
||
57 | $this->composer->expects($this->any())->method('getPluginManager') |
||
58 | ->willReturn(new PluginManager($this->io, $this->composer)); |
||
59 | $this->composer->expects($this->any())->method('getEventDispatcher') |
||
60 | ->willReturn(new EventDispatcher($this->composer, $this->io)); |
||
61 | $this->composer->expects($this->any())->method('getRepositoryManager') |
||
62 | ->willReturn(new RepositoryManager($this->io, new Config())); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @dataProvider getTestOptionsData |
||
67 | * |
||
68 | * @param array|null $configData |
||
69 | * @param array $expectedOptions |
||
70 | */ |
||
71 | public function testOptions($configData, array $expectedOptions) |
||
72 | { |
||
73 | if (null === $configData) { |
||
74 | $this->composer->expects($this->any())->method('getConfig') |
||
|
|||
75 | ->willReturn(null); |
||
76 | } else { |
||
77 | $this->config->merge($configData); |
||
78 | } |
||
79 | |||
80 | $plugin = new VersionsCheckPlugin(); |
||
81 | $plugin->activate($this->composer, $this->io); |
||
82 | |||
83 | $this->assertAttributeSame($expectedOptions, 'options', $plugin); |
||
84 | } |
||
85 | |||
86 | public function getTestOptionsData() |
||
87 | { |
||
88 | return array( |
||
89 | 'No option' => array( |
||
90 | null, |
||
91 | array( |
||
92 | 'show-links' => true, |
||
93 | ), |
||
94 | ), |
||
95 | 'Empty array options' => array( |
||
96 | array(), |
||
97 | array( |
||
98 | 'show-links' => true, |
||
99 | ), |
||
100 | ), |
||
101 | 'Empty array plugin options' => array( |
||
102 | array( |
||
103 | 'config' => array( |
||
104 | 'sllh-composer-versions-check' => array(), |
||
105 | ), |
||
106 | ), |
||
107 | array( |
||
108 | 'show-links' => true, |
||
109 | ), |
||
110 | ), |
||
111 | 'Empty plugin options' => array( |
||
112 | array( |
||
113 | 'config' => array( |
||
114 | 'sllh-composer-versions-check' => null, |
||
115 | ), |
||
116 | ), |
||
117 | array( |
||
118 | 'show-links' => true, |
||
119 | ), |
||
120 | ), |
||
121 | 'False plugin options' => array( |
||
122 | array( |
||
123 | 'config' => array( |
||
124 | 'sllh-composer-versions-check' => false, |
||
125 | ), |
||
126 | ), |
||
127 | array( |
||
128 | 'show-links' => true, |
||
129 | ), |
||
130 | ), |
||
131 | 'Activate show-links' => array( |
||
132 | array( |
||
133 | 'config' => array( |
||
134 | 'sllh-composer-versions-check' => array( |
||
135 | 'show-links' => true, |
||
136 | ), |
||
137 | ), |
||
138 | ), |
||
139 | array( |
||
140 | 'show-links' => true, |
||
141 | ), |
||
142 | ), |
||
143 | 'Disable show-links' => array( |
||
144 | array( |
||
145 | 'config' => array( |
||
146 | 'sllh-composer-versions-check' => array( |
||
147 | 'show-links' => false, |
||
148 | ), |
||
149 | ), |
||
150 | ), |
||
151 | array( |
||
152 | 'show-links' => false, |
||
153 | ), |
||
154 | ), |
||
155 | ); |
||
156 | } |
||
157 | |||
158 | public function testPluginRegister() |
||
168 | |||
169 | public function testUpdateCommand() |
||
170 | { |
||
171 | $this->addComposerPlugin(new VersionsCheckPlugin()); |
||
172 | |||
173 | $localRepository = new WritableArrayRepository(); |
||
174 | $localRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
175 | $this->composer->getRepositoryManager()->setLocalRepository($localRepository); |
||
176 | |||
177 | $distRepository = new ArrayRepository(); |
||
178 | $distRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
179 | $distRepository->addPackage(new Package('foo/bar', '1.0.1', '1.0.1')); |
||
180 | $distRepository->addPackage(new Package('foo/bar', '2.0.0', '2.0.0')); |
||
181 | $this->composer->getRepositoryManager()->addRepository($distRepository); |
||
182 | |||
183 | $this->composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_UPDATE_CMD); |
||
184 | |||
185 | $this->assertSameOutput(<<<'EOF' |
||
186 | <warning>1 package is not up to date:</warning> |
||
187 | |||
188 | - foo/bar (1.0.0) latest is 2.0.0 |
||
189 | |||
190 | |||
191 | EOF |
||
192 | ); |
||
193 | } |
||
194 | |||
195 | public function testPreferLowest() |
||
217 | |||
218 | public function testPreferLowestNotExists() |
||
219 | { |
||
220 | $this->addComposerPlugin(new VersionsCheckPlugin()); |
||
221 | |||
222 | $localRepository = new WritableArrayRepository(); |
||
223 | $localRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
224 | $this->composer->getRepositoryManager()->setLocalRepository($localRepository); |
||
225 | |||
226 | $distRepository = new ArrayRepository(); |
||
227 | $distRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
228 | $distRepository->addPackage(new Package('foo/bar', '2.0.0', '2.0.0')); |
||
229 | $this->composer->getRepositoryManager()->addRepository($distRepository); |
||
230 | |||
231 | $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'update', new ArrayInput(array()), new NullOutput()); |
||
232 | $this->composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); |
||
233 | $this->composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_UPDATE_CMD); |
||
234 | |||
235 | $this->assertSameOutput(<<<'EOF' |
||
236 | <warning>1 package is not up to date:</warning> |
||
237 | |||
238 | - foo/bar (1.0.0) latest is 2.0.0 |
||
239 | |||
240 | |||
241 | EOF |
||
242 | ); |
||
243 | } |
||
244 | |||
245 | private function addComposerPlugin(PluginInterface $plugin) |
||
252 | |||
253 | private function assertSameOutput($expectedOutput, $message = '') |
||
254 | { |
||
255 | if ('@package_version@' === Composer::VERSION) { |
||
256 | $expectedOutput = "<warning>You are running an unstable version of composer." |
||
257 | ." The sllh/composer-versions-check plugin might not works as expected.</warning>\n" |
||
263 | } |
||
264 |
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.