Skip to content

Commit

Permalink
fix(app-builder): remove composer install from scope php action
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Jul 24, 2024
1 parent 85800ea commit 4e476b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
5 changes: 2 additions & 3 deletions apps/app-builder/src/commands/scopePhp/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import path from 'path';
import {composerInstall, exists, resolveString, usesPhpScoper} from '../../utils';
import {exists, resolveString, usesPhpScoper} from '../../utils';
import {type PdkBuilderCommand} from '../../types';
import {runPhpScoper} from './runPhpScoper';
import {installPhpScoper} from './installPhpScoper';

const scopePhp: PdkBuilderCommand = async (context) => {
const {env, config, args, debug} = context;
const {env, config, debug} = context;
const {vendorConfigFile, outDir, vendorOutDir} = config.phpScoper;

if (!(await usesPhpScoper(context))) {
return;
}

await composerInstall(context, ['--no-dev']);
await installPhpScoper(context);

debug('Scoping php files...');
Expand Down
21 changes: 6 additions & 15 deletions apps/app-builder/src/commands/scopePhp/scopePhp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,10 @@ import {resolveString} from '../../utils';
import {type PdkBuilderContext} from '../../types';
import {fsModifyingMethodSpies} from '../../__tests__/spies/fs';
import {mockFileSystemAndCreateContext} from '../../__tests__/mockFileSystemAndCreateContext';
import {MOCK_ROOT_DIR} from '../../__tests__/constants';
import {PACKAGE_NAME} from './constants';

const mockStdout = vi.fn(() => '');

const ARGS_COMPOSER_INSTALL = [
'composer',
expect.arrayContaining(['install', '--no-dev']),
expect.objectContaining({cwd: expect.stringContaining(MOCK_ROOT_DIR)}),
];

const getScoperInstallArgs = (context: PdkBuilderContext) => {
const {installDir, version} = context.config.phpScoper;

Expand Down Expand Up @@ -51,7 +44,7 @@ vi.mock('child_process', () => ({

describe('command: scopePhp', () => {
it("installs php scoper if it isn't installed yet", async (ctx) => {
expect.assertions(4);
expect.assertions(3);
const INSTALL_DIR = '.scoped/php-scoper';

const context = await mockFileSystemAndCreateContext(
Expand All @@ -77,14 +70,13 @@ describe('command: scopePhp', () => {
await scopePhp(context);
const {outDir, vendorOutDir} = context.config.phpScoper;

expect(child_process.spawnSync).toHaveBeenNthCalledWith(1, ...ARGS_COMPOSER_INSTALL);
expect(child_process.spawnSync).toHaveBeenNthCalledWith(2, ...getScoperInstallArgs(context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(3, ...getScoperRunArgs(vendorOutDir, context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(4, ...getScoperRunArgs(outDir, context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(1, ...getScoperInstallArgs(context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(2, ...getScoperRunArgs(vendorOutDir, context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(3, ...getScoperRunArgs(outDir, context));
});

it('skips install if php scoper is already installed', async (ctx) => {
expect.assertions(3);
expect.assertions(2);
const context = await mockFileSystemAndCreateContext(
ctx,
{
Expand All @@ -109,8 +101,7 @@ describe('command: scopePhp', () => {
const {outDir} = context.config.phpScoper;

expect(child_process.spawnSync).not.toHaveBeenCalledWith(...getScoperInstallArgs(context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(1, ...ARGS_COMPOSER_INSTALL);
expect(child_process.spawnSync).toHaveBeenNthCalledWith(2, ...getScoperRunArgs(outDir, context));
expect(child_process.spawnSync).toHaveBeenNthCalledWith(1, ...getScoperRunArgs(outDir, context));
});

it('does not do anything if php scoper is disabled', async (ctx) => {
Expand Down

0 comments on commit 4e476b5

Please sign in to comment.