Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#52 Fixing the lock file #73

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Instead of installing the packages you're working on from the Packagist reposito
Under the hood, it uses Composer's [path repositories](https://getcomposer.org/doc/05-repositories.md#path) to do so.
As a result, you won't have to develop in the `vendor` directory.

To maintain the integrity of the `composer.lock` file, studio creates a `.studio` directory to keep the original packages from Packagist.

Studio also knows how to configure development tools that might be part of your workflow.
This includes the following:

Expand Down Expand Up @@ -65,16 +67,19 @@ And finally, tell Studio to set up the symlinks:

If all goes well, you should now see a brief message along the following as part of Composer's output:

> [Studio] Loading path installer
> [Studio] Creating link to path/to/world-domination for package my/world-domination

This is what will happen under the hood:

1. Composer begins checking dependencies for updates.
2. Studio jumps in and informs Composer to prefer packages from the directories listed in the `studio.json` file over downloading them from Packagist.
3. Composer symlinks these packages into the `vendor` directory or any other appropriate place (e.g. for [custom installers](https://getcomposer.org/doc/articles/custom-installers.md)).
1. Studio will restore all original packages from the `.studio` directory that were managed by studio.
2. Composer begins checking dependencies for updates.
3. When Composer installed all packages into the `vendor` directory studio jumps in and re installs all packages
listed in the `studio.json` with the [path repository](https://getcomposer.org/doc/05-repositories.md#path) installer.
The original packages are stored in the `.studio` directory.
4. Composer symlinks these packages into the `vendor` directory or any other appropriate place (e.g. for [custom installers](https://getcomposer.org/doc/articles/custom-installers.md)).
Thus, to your application, these packages will behave just like "normal" Composer packages.
4. Composer generates proper autoloading rules for the Studio packages.
5. For non-Studio packages, Composer works as always.
5. Composer generates proper autoloading rules for the Studio packages.
6. For non-Studio packages, Composer works as always.

**Pro tip:** If you keep all your libraries in one directory, you can let Studio find all of them by using a wildcard:

Expand Down
171 changes: 171 additions & 0 deletions spec/Composer/StudioPluginSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

namespace spec\Studio\Composer;

use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Script\ScriptEvents;
use PhpSpec\ObjectBehavior;

class StudioPluginSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Studio\Composer\StudioPlugin');
}

function it_is_activatable(Composer $composer, IOInterface $io)
{
$this->activate($composer, $io);
}

function it_resolves_subscribed_events()
{
self::getSubscribedEvents()->shouldReturn([
ScriptEvents::PRE_UPDATE_CMD => 'unlinkStudioPackages',
ScriptEvents::POST_UPDATE_CMD => 'symlinkStudioPackages',
ScriptEvents::POST_INSTALL_CMD => 'symlinkStudioPackages',
ScriptEvents::PRE_AUTOLOAD_DUMP => 'symlinkStudioPackages'
]);
}

/**
* Test if studio does not create symlinks when no studio.json is defined
*/
function it_doesnt_create_symlinks_without_file($composer, $io, $rootPackage, $filesystem)
{
// switch working directory
chdir(__DIR__);

// create stubs
$filesystem->beADoubleOf('Composer\Util\Filesystem');
$rootPackage->beADoubleOf('Composer\Package\RootPackage');
$composer->beADoubleOf('Composer\Composer');
$io->beADoubleOf('Composer\IO\IOInterface');

// Construct
$this->beConstructedWith($filesystem);

// Mock methods
$composer->getInstallationManager()->willReturn(null);
$composer->getDownloadManager()->willReturn(null);
$composer->getPackage()->willReturn($rootPackage);
$rootPackage->getTargetDir()->willReturn(getcwd());

// Test
$this->activate($composer, $io);
$this->symlinkStudioPackages();
}

/**
* Test if studio does not unlink when no studio.json or .studio/studio.json is defined
*/
function it_doesnt_unlink_without_files($composer, $io, $rootPackage, $filesystem)
{
// switch working directory
chdir(__DIR__);

// create stubs
$filesystem->beADoubleOf('Composer\Util\Filesystem');
$rootPackage->beADoubleOf('Composer\Package\RootPackage');
$composer->beADoubleOf('Composer\Composer');
$io->beADoubleOf('Composer\IO\IOInterface');

// Construct
$this->beConstructedWith($filesystem);

// Mock methods
$composer->getInstallationManager()->willReturn(null);
$composer->getDownloadManager()->willReturn(null);
$composer->getPackage()->willReturn($rootPackage);
$rootPackage->getTargetDir()->willReturn(getcwd());

// Test
$this->activate($composer, $io);
$this->unlinkStudioPackages();
}

/**
* Test if studio does create symlinks when studio.json is defined
*/
function it_does_create_symlinks_with_file(
$composer,
$io,
$rootPackage,
$filesystem,
$installationManager,
$downloadManager,
$pathDownloader
) {
// switch working directory
chdir(__DIR__ . '/stubs/project-with-path');

// create stubs
$filesystem->beADoubleOf('Composer\Util\Filesystem');
$rootPackage->beADoubleOf('Composer\Package\RootPackage');
$composer->beADoubleOf('Composer\Composer');
$io->beADoubleOf('Composer\IO\IOInterface');
$installationManager->beADoubleOf('Composer\Installer\InstallationManager');
$downloadManager->beADoubleOf('Composer\Downloader\DownloadManager');
$pathDownloader->beADoubleOf('Composer\Downloader\PathDownloader');

// Construct
//$this->beConstructedWith($filesystem);

// Mock methods
$composer->getInstallationManager()->willReturn($installationManager);
$composer->getDownloadManager()->willReturn($downloadManager);
$composer->getPackage()->willReturn($rootPackage);
$rootPackage->getTargetDir()->willReturn(getcwd());
$downloadManager->getDownloader('path')
->willReturn($pathDownloader)
->shouldBeCalled();

$io->write('[Studio] Creating link to library for package acme/library')->shouldBeCalled();

// Test
$this->activate($composer, $io);
$this->symlinkStudioPackages();
}


/**
* Test if studio does unlink when studio.json is defined
*/
function it_does_unlink_with_file(
$composer,
$io,
$rootPackage,
$filesystem,
$installationManager,
$pathDownloader
) {
// switch working directory
chdir(__DIR__ . '/stubs/project-with-unload');

// create stubs
$filesystem->beADoubleOf('Composer\Util\Filesystem');
$rootPackage->beADoubleOf('Composer\Package\RootPackage');
$composer->beADoubleOf('Composer\Composer');
$io->beADoubleOf('Composer\IO\IOInterface');
$installationManager->beADoubleOf('Composer\Installer\InstallationManager');
$pathDownloader->beADoubleOf('Composer\Downloader\PathDownloader');

// Construct
$this->beConstructedWith($filesystem);

// Mock methods
$composer->getInstallationManager()->willReturn($installationManager);
$composer->getDownloadManager()->willReturn(null);
$composer->getPackage()->willReturn($rootPackage);
$rootPackage->getTargetDir()->willReturn(getcwd());
$filesystem->isSymlinkedDirectory(null)->willReturn(true)->shouldBeCalled();
$filesystem->removeDirectory(null)->shouldBeCalled();

$io->write('[Studio] Removing linked path library for package acme/library')->shouldBeCalled();

// Test
$this->activate($composer, $io);
$this->unlinkStudioPackages();
}
}
3 changes: 3 additions & 0 deletions spec/Composer/stubs/project-with-path/library/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "acme/library"
}
6 changes: 6 additions & 0 deletions spec/Composer/stubs/project-with-path/studio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 2,
"paths": [
"library"
]
}
6 changes: 6 additions & 0 deletions spec/Composer/stubs/project-with-unload/.studio/studio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": 2,
"paths": [
"library"
]
}
3 changes: 3 additions & 0 deletions spec/Composer/stubs/project-with-unload/library/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "acme/library"
}
4 changes: 4 additions & 0 deletions spec/Composer/stubs/project-with-unload/studio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": 2,
"paths": []
}
Loading