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 | * {@inheritdoc} |
||
41 | */ |
||
42 | protected function setUp() |
||
43 | { |
||
44 | $this->io = new BufferIO(); |
||
45 | $this->composer = $this->getMock('Composer\Composer'); |
||
46 | |||
47 | $this->composer->expects($this->any())->method('getPackage') |
||
48 | ->willReturn(new RootPackage('my/project', '1.0.0', '1.0.0')); |
||
49 | $this->composer->expects($this->any())->method('getPluginManager') |
||
50 | ->willReturn(new PluginManager($this->io, $this->composer)); |
||
51 | $this->composer->expects($this->any())->method('getEventDispatcher') |
||
52 | ->willReturn(new EventDispatcher($this->composer, $this->io)); |
||
53 | $this->composer->expects($this->any())->method('getRepositoryManager') |
||
54 | ->willReturn(new RepositoryManager($this->io, new Config())); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @dataProvider getTestOptionsData |
||
59 | * |
||
60 | * @param array|null $configData |
||
61 | * @param array $expectedOptions |
||
62 | */ |
||
63 | public function testOptions($configData, array $expectedOptions) |
||
64 | { |
||
65 | if (null === $configData) { |
||
66 | $this->composer->expects($this->any())->method('getConfig') |
||
|
|||
67 | ->willReturn(null); |
||
68 | } else { |
||
69 | $config = new Config(false); |
||
70 | $config->merge($configData); |
||
71 | $this->composer->expects($this->any())->method('getConfig') |
||
72 | ->willReturn($config); |
||
73 | } |
||
74 | |||
75 | $plugin = new VersionsCheckPlugin(); |
||
76 | $plugin->activate($this->composer, $this->io); |
||
77 | |||
78 | $this->assertAttributeSame($expectedOptions, 'options', $plugin); |
||
79 | } |
||
80 | |||
81 | public function getTestOptionsData() |
||
82 | { |
||
83 | return array( |
||
84 | array( |
||
85 | null, |
||
86 | array( |
||
87 | 'show-links' => true, |
||
88 | ), |
||
89 | ), |
||
90 | array( |
||
91 | array(), |
||
92 | array( |
||
93 | 'show-links' => true, |
||
94 | ), |
||
95 | ), |
||
96 | array( |
||
97 | array( |
||
98 | 'config' => array( |
||
99 | 'sllh-composer-versions-check' => array(), |
||
100 | ), |
||
101 | ), |
||
102 | array( |
||
103 | 'show-links' => true, |
||
104 | ), |
||
105 | ), |
||
106 | array( |
||
107 | array( |
||
108 | 'config' => array( |
||
109 | 'sllh-composer-versions-check' => null, |
||
110 | ), |
||
111 | ), |
||
112 | array( |
||
113 | 'show-links' => true, |
||
114 | ), |
||
115 | ), |
||
116 | array( |
||
117 | array( |
||
118 | 'config' => array( |
||
119 | 'sllh-composer-versions-check' => false, |
||
120 | ), |
||
121 | ), |
||
122 | array( |
||
123 | 'show-links' => true, |
||
124 | ), |
||
125 | ), |
||
126 | array( |
||
127 | array( |
||
128 | 'config' => array( |
||
129 | 'sllh-composer-versions-check' => array( |
||
130 | 'show-links' => true, |
||
131 | ), |
||
132 | ), |
||
133 | ), |
||
134 | array( |
||
135 | 'show-links' => true, |
||
136 | ), |
||
137 | ), |
||
138 | array( |
||
139 | array( |
||
140 | 'config' => array( |
||
141 | 'sllh-composer-versions-check' => array( |
||
142 | 'show-links' => false, |
||
143 | ), |
||
144 | ), |
||
145 | ), |
||
146 | array( |
||
147 | 'show-links' => false, |
||
148 | ), |
||
149 | ), |
||
150 | ); |
||
151 | } |
||
152 | |||
153 | public function testPluginRegister() |
||
154 | { |
||
155 | $plugin = new VersionsCheckPlugin(); |
||
156 | $this->addComposerPlugin($plugin); |
||
157 | |||
158 | $this->assertSame(array($plugin), $this->composer->getPluginManager()->getPlugins()); |
||
159 | $this->assertAttributeInstanceOf('Composer\Composer', 'composer', $plugin); |
||
160 | $this->assertAttributeInstanceOf('Composer\IO\IOInterface', 'io', $plugin); |
||
161 | $this->assertAttributeInstanceOf('SLLH\ComposerVersionsCheck\VersionsCheck', 'versionsCheck', $plugin); |
||
162 | } |
||
163 | |||
164 | public function testUpdateCommand() |
||
165 | { |
||
166 | $this->addComposerPlugin(new VersionsCheckPlugin()); |
||
167 | |||
168 | $localRepository = new WritableArrayRepository(); |
||
169 | $localRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
170 | $this->composer->getRepositoryManager()->setLocalRepository($localRepository); |
||
171 | |||
172 | $distRepository = new ArrayRepository(); |
||
173 | $distRepository->addPackage(new Package('foo/bar', '1.0.0', '1.0.0')); |
||
174 | $distRepository->addPackage(new Package('foo/bar', '1.0.1', '1.0.1')); |
||
175 | $distRepository->addPackage(new Package('foo/bar', '2.0.0', '2.0.0')); |
||
176 | $this->composer->getRepositoryManager()->addRepository($distRepository); |
||
177 | |||
178 | $this->composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_UPDATE_CMD); |
||
179 | |||
180 | $this->assertSame(<<<'EOF' |
||
181 | <warning>1 package is not up to date:</warning> |
||
182 | |||
183 | - foo/bar (1.0.0) latest is 2.0.0 |
||
184 | |||
185 | |||
186 | EOF |
||
187 | , $this->io->getOutput()); |
||
188 | } |
||
189 | |||
190 | public function testPreferLowest() |
||
212 | |||
213 | public function testPreferLowestNotExists() |
||
214 | { |
||
215 | $this->addComposerPlugin(new VersionsCheckPlugin()); |
||
216 | |||
217 | $localRepository = new WritableArrayRepository(); |
||
239 | |||
240 | private function addComposerPlugin(PluginInterface $plugin) |
||
247 | } |
||
248 |
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.