Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 23, 2022
1 parent 9e60202 commit 294e7b8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/function/ConsoleFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { PhpFunction, PhpFunctionProps } from './PhpFunction';

export class ConsoleFunction extends PhpFunction {
constructor(scope: Construct, id: string, props: PhpFunctionProps) {
const layers = props.layers ?? [];
layers.unshift(consoleLayer(scope, Stack.of(scope).region));
super(scope, id, {
...props,
layers,
});
super(scope, id, props);

this.addLayers(consoleLayer(this, Stack.of(scope).region));
}
}
4 changes: 2 additions & 2 deletions src/function/PhpFpmFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PhpFpmFunction extends Function {
layers: [],
});

// Add layer afterwards so that we can use `this` to resolve the region
// Add layer afterwards so that we can use `this`
const region = Stack.of(this).region;
if (region.startsWith('${')) {
throw new Error(
Expand All @@ -43,7 +43,7 @@ export class PhpFpmFunction extends Function {
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
this.addLayers(
// Add the FPM layer first so that other layers can override it
fpmLayer(scope, region, phpVersion, functionDefaults.platform),
fpmLayer(this, region, phpVersion, functionDefaults.platform),
...layers
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/function/PhpFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class PhpFunction extends Function {
layers: [],
});

// Add layer afterwards so that we can use `this` to resolve the region
// Add layer afterwards so that we can use `this`
const region = Stack.of(this).region;
if (region.startsWith('${')) {
throw new Error(
Expand All @@ -44,7 +44,7 @@ export class PhpFunction extends Function {
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
this.addLayers(
// Add the function layer first so that other layers can override it
functionLayer(scope, region, phpVersion, functionDefaults.platform),
functionLayer(this, region, phpVersion, functionDefaults.platform),
...layers
);
}
Expand Down
16 changes: 15 additions & 1 deletion test/function/ConsoleFunction.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { ConsoleFunction } from '../../src/function/ConsoleFunction';
import { ConsoleFunction } from '../../src';
import { compileTestStack } from '../helper';

describe('ConsoleFunction', () => {
Expand All @@ -16,4 +16,18 @@ describe('ConsoleFunction', () => {
expect(layers[0]).to.match(/arn:aws:lambda:us-east-1:534081306603:layer:php-81:\d+/);
expect(layers[1]).to.match(/arn:aws:lambda:us-east-1:534081306603:layer:console:\d+/);
});

// https://github.com/brefphp/constructs/issues/1
it('can build multiple functions in the same stack', () => {
const template = compileTestStack((stack) => {
new ConsoleFunction(stack, 'Function1', {
handler: 'index.php',
});
new ConsoleFunction(stack, 'Function2', {
handler: 'index.php',
});
});

template.resourceCountIs('AWS::Lambda::Function', 2);
});
});
14 changes: 11 additions & 3 deletions test/function/PhpFpmFunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import { cleanupTemplate, compileTestStack } from '../helper';
describe('PhpFpmFunction', () => {
it('builds', () => {
const template = compileTestStack((stack) => {
new PhpFpmFunction(stack, 'Function', {
handler: 'index.php',
});
new PhpFpmFunction(stack, 'Function');
}).toJSON();

expect(cleanupTemplate(template).Resources).toMatchSnapshot();
});

// https://github.com/brefphp/constructs/issues/1
it('can build multiple functions in the same stack', () => {
const template = compileTestStack((stack) => {
new PhpFpmFunction(stack, 'Function1');
new PhpFpmFunction(stack, 'Function2');
});

template.resourceCountIs('AWS::Lambda::Function', 2);
});
});
14 changes: 14 additions & 0 deletions test/function/PhpFunction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,18 @@ describe('PhpFunction', () => {

expect(cleanupTemplate(template).Resources).toMatchSnapshot();
});

// https://github.com/brefphp/constructs/issues/1
it('can build multiple functions in the same stack', () => {
const template = compileTestStack((stack) => {
new PhpFunction(stack, 'Function1', {
handler: 'index.php',
});
new PhpFunction(stack, 'Function2', {
handler: 'index.php',
});
});

template.resourceCountIs('AWS::Lambda::Function', 2);
});
});

0 comments on commit 294e7b8

Please sign in to comment.