123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace Composer\Test\Util;
- use Composer\Util\Zip;
- use Composer\Test\TestCase;
- class ZipTest extends TestCase
- {
- public function testThrowsExceptionIfZipExcentionIsNotLoaded()
- {
- if (extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is loaded.');
- }
- $this->setExpectedException('\RuntimeException', 'The Zip Util requires PHP\'s zip extension');
- Zip::getComposerJson('');
- }
- public function testReturnsNullifTheZipIsNotFound()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/invalid.zip');
- $this->assertNull($result);
- }
- public function testReturnsNullIfTheZipIsEmpty()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/empty.zip');
- $this->assertNull($result);
- }
- public function testReturnsNullIfTheZipHasNoComposerJson()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/nojson.zip');
- $this->assertNull($result);
- }
- public function testReturnsNullIfTheComposerJsonIsInASubSubfolder()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/subfolder.zip');
- $this->assertNull($result);
- }
- public function testReturnsComposerJsonInZipRoot()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/root.zip');
- $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result);
- }
- public function testReturnsComposerJsonInFirstFolder()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/folder.zip');
- $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result);
- }
- public function testReturnsRootComposerJsonAndSkipsSubfolders()
- {
- if (!extension_loaded('zip')) {
- $this->markTestSkipped('The PHP zip extension is not loaded.');
- return;
- }
- $result = Zip::getComposerJson(__DIR__.'/Fixtures/Zip/multiple.zip');
- $this->assertEquals("{\n \"name\": \"foo/bar\"\n}\n", $result);
- }
- }
|