1 | <?php |
||||||
2 | |||||||
3 | namespace BringYourOwnIdeas\UpdateChecker\Tests; |
||||||
4 | |||||||
5 | use BringYourOwnIdeas\Maintenance\Util\ComposerLoader; |
||||||
6 | use BringYourOwnIdeas\UpdateChecker\UpdateChecker; |
||||||
7 | use Composer\Composer; |
||||||
8 | use PHPUnit_Framework_TestCase; |
||||||
0 ignored issues
–
show
|
|||||||
9 | use SilverStripe\Core\Injector\Injector; |
||||||
10 | use SilverStripe\Dev\SapphireTest; |
||||||
11 | |||||||
12 | /** |
||||||
13 | * @mixin PHPUnit_Framework_TestCase |
||||||
14 | */ |
||||||
15 | class UpdateCheckerTest extends SapphireTest |
||||||
16 | { |
||||||
17 | protected $usesDatabase = true; |
||||||
18 | |||||||
19 | /** |
||||||
20 | * @var UpdateChecker |
||||||
21 | */ |
||||||
22 | protected $updateChecker; |
||||||
23 | |||||||
24 | protected function setUp(): void |
||||||
25 | { |
||||||
26 | parent::setUp(); |
||||||
27 | |||||||
28 | // Mock composer and composer loader |
||||||
29 | $composer = $this->getMockBuilder(Composer::Class)->getMock(); |
||||||
0 ignored issues
–
show
|
|||||||
30 | $composerLoader = $this->getMockBuilder(ComposerLoader::class) |
||||||
31 | ->disableOriginalConstructor() |
||||||
32 | ->setMethods(['getComposer']) |
||||||
33 | ->getMock(); |
||||||
34 | $composerLoader->expects($this->once())->method('getComposer')->will($this->returnValue($composer)); |
||||||
35 | Injector::inst()->registerService($composerLoader, ComposerLoader::class); |
||||||
36 | |||||||
37 | // Partially mock UpdateChecker |
||||||
38 | $this->updateChecker = $this->getMockBuilder(UpdateChecker::class) |
||||||
39 | ->setMethods(['findLatestPackage']) |
||||||
40 | ->getMock(); |
||||||
41 | } |
||||||
42 | |||||||
43 | public function testCheckForUpdates() |
||||||
44 | { |
||||||
45 | $mockPackage = new \Composer\Package\Package('foo/bar', '2.3.4.0', '2.3.4'); |
||||||
46 | $mockPackage->setSourceReference('foobar123'); |
||||||
47 | |||||||
48 | // No available update |
||||||
49 | $this->updateChecker->expects($this->at(0)) |
||||||
0 ignored issues
–
show
The method
expects() does not exist on BringYourOwnIdeas\UpdateChecker\UpdateChecker .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. ![]() |
|||||||
50 | ->method('findLatestPackage') |
||||||
51 | ->will($this->returnValue(false)); |
||||||
52 | |||||||
53 | // There is latest version though |
||||||
54 | $this->updateChecker->expects($this->at(1)) |
||||||
55 | ->method('findLatestPackage') |
||||||
56 | ->will($this->returnValue($mockPackage)); |
||||||
57 | |||||||
58 | $result = $this->updateChecker->checkForUpdates($mockPackage, '~1.2.0'); |
||||||
59 | $this->assertArrayNotHasKey('AvailableVersion', $result, 'No available update is recorded'); |
||||||
60 | $this->assertArrayNotHasKey('AvailableHash', $result, 'No available update is recorded'); |
||||||
61 | $this->assertSame('2.3.4', $result['LatestVersion'], 'Latest version is returned'); |
||||||
62 | $this->assertSame('foobar123', $result['LatestHash'], 'Hash of latest version is returned'); |
||||||
63 | } |
||||||
64 | } |
||||||
65 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths