Skip to content
This repository was archived by the owner on Jul 8, 2024. It is now read-only.

Commit e60258e

Browse files
xemlockgarak
authored andcommitted
Fix install dependencies for GitHub packages (#159)
* Fix install dependencies for GitHub packages * Add tests
1 parent 958bcc0 commit e60258e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Bowerphp/Installer/Installer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public function install(PackageInterface $package)
7575
}
7676
$this->zipArchive->close();
7777

78+
// merge package info with bower.json contents
79+
$bowerJsonPath = $this->config->getInstallDir() . '/' . $package->getName() . '/bower.json';
80+
if ($this->filesystem->exists($bowerJsonPath)) {
81+
$bowerJson = $this->filesystem->read($bowerJsonPath);
82+
$bower = json_decode($bowerJson, true);
83+
$package->setInfo(array_merge($bower, $package->getInfo()));
84+
}
85+
7886
// create .bower.json metadata file
7987
// XXX we still need to add some other info
8088
$dotBowerContent = array_merge($package->getInfo(), ['version' => $package->getVersion()]);

tests/Bowerphp/Test/Installer/InstallerTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function testInstall()
5656
}';
5757

5858
$this->filesystem
59+
->shouldReceive('exists')->with(getcwd() . '/bower_components/jquery/bower.json')->andReturn(false)
5960
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery/foo', 'foo content')
6061
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery/.bower.json', $json)
6162
->shouldReceive('touch')->with(getcwd() . '/bower_components/jquery/foo', 1396303200)
@@ -90,6 +91,7 @@ public function testUpdate()
9091
}';
9192

9293
$this->filesystem
94+
->shouldReceive('exists')->with(getcwd() . '/bower_components/jquery/bower.json')->andReturn(false)
9395
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery/foo', 'foo content')
9496
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery/.bower.json', $json)
9597
->shouldReceive('touch')->with(getcwd() . '/bower_components/jquery/foo', 1396303200)
@@ -98,6 +100,52 @@ public function testUpdate()
98100
$this->installer->update($package);
99101
}
100102

103+
public function testInstallAndMergeInfoWithBowerJsonContents()
104+
{
105+
$package = Mockery::mock('Bowerphp\Package\PackageInterface');
106+
107+
$info = [
108+
'name' => 'jquery-ui',
109+
'version' => '1.12.1',
110+
'dependencies' => [
111+
'jquery' => '>=1.6',
112+
],
113+
];
114+
115+
$package
116+
->shouldReceive('getName')->andReturn('jquery-ui')
117+
->shouldReceive('getVersion')->andReturn('1.12.1')
118+
->shouldReceive('getInfo')->andReturn([])->once()
119+
->shouldReceive('setInfo')->with($info)->andReturnSelf()
120+
->shouldReceive('getInfo')->andReturn($info);
121+
122+
$json = '{
123+
"name": "jquery-ui",
124+
"version": "1.12.1",
125+
"dependencies": {
126+
"jquery": ">=1.6"
127+
}
128+
}';
129+
130+
$this->zipArchive
131+
->shouldReceive('open')->with('./tmp/jquery-ui')->andReturn(true)
132+
->shouldReceive('getNumFiles')->andReturn(1)
133+
->shouldReceive('getNameIndex')->with(0)->andReturn('jquery-ui')
134+
->shouldReceive('statIndex')->andReturn(['name' => 'jquery-ui/bower.json', 'size' => 107, 'mtime' => 1483795099])
135+
->shouldReceive('getStream')->with('jquery-ui/bower.json')->andReturn($json)
136+
->shouldReceive('close');
137+
138+
$this->filesystem
139+
->shouldReceive('exists')->with(getcwd() . '/bower_components/jquery-ui/bower.json')->andReturn(true)
140+
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery-ui/.bower.json', $json)
141+
->shouldReceive('write')->with(getcwd() . '/bower_components/jquery-ui/bower.json', $json)
142+
->shouldReceive('touch')->with(getcwd() . '/bower_components/jquery-ui/bower.json', 1483795099)
143+
->shouldReceive('read')->with(getcwd() . '/bower_components/jquery-ui/bower.json')->andReturn($json)
144+
;
145+
146+
$this->installer->install($package);
147+
}
148+
101149
/**
102150
* @expectedException \RuntimeException
103151
* @expectedExceptionMessage Unable to open zip file ./tmp/jquery.

0 commit comments

Comments
 (0)