Skip to content

Commit 294e7b8

Browse files
committed
Fix #1
1 parent 9e60202 commit 294e7b8

File tree

6 files changed

+47
-14
lines changed

6 files changed

+47
-14
lines changed

src/function/ConsoleFunction.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import { PhpFunction, PhpFunctionProps } from './PhpFunction';
55

66
export class ConsoleFunction extends PhpFunction {
77
constructor(scope: Construct, id: string, props: PhpFunctionProps) {
8-
const layers = props.layers ?? [];
9-
layers.unshift(consoleLayer(scope, Stack.of(scope).region));
10-
super(scope, id, {
11-
...props,
12-
layers,
13-
});
8+
super(scope, id, props);
9+
10+
this.addLayers(consoleLayer(this, Stack.of(scope).region));
1411
}
1512
}

src/function/PhpFpmFunction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class PhpFpmFunction extends Function {
3333
layers: [],
3434
});
3535

36-
// Add layer afterwards so that we can use `this` to resolve the region
36+
// Add layer afterwards so that we can use `this`
3737
const region = Stack.of(this).region;
3838
if (region.startsWith('${')) {
3939
throw new Error(
@@ -43,7 +43,7 @@ export class PhpFpmFunction extends Function {
4343
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
4444
this.addLayers(
4545
// Add the FPM layer first so that other layers can override it
46-
fpmLayer(scope, region, phpVersion, functionDefaults.platform),
46+
fpmLayer(this, region, phpVersion, functionDefaults.platform),
4747
...layers
4848
);
4949
}

src/function/PhpFunction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class PhpFunction extends Function {
3434
layers: [],
3535
});
3636

37-
// Add layer afterwards so that we can use `this` to resolve the region
37+
// Add layer afterwards so that we can use `this`
3838
const region = Stack.of(this).region;
3939
if (region.startsWith('${')) {
4040
throw new Error(
@@ -44,7 +44,7 @@ export class PhpFunction extends Function {
4444
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
4545
this.addLayers(
4646
// Add the function layer first so that other layers can override it
47-
functionLayer(scope, region, phpVersion, functionDefaults.platform),
47+
functionLayer(this, region, phpVersion, functionDefaults.platform),
4848
...layers
4949
);
5050
}

test/function/ConsoleFunction.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { ConsoleFunction } from '../../src/function/ConsoleFunction';
2+
import { ConsoleFunction } from '../../src';
33
import { compileTestStack } from '../helper';
44

55
describe('ConsoleFunction', () => {
@@ -16,4 +16,18 @@ describe('ConsoleFunction', () => {
1616
expect(layers[0]).to.match(/arn:aws:lambda:us-east-1:534081306603:layer:php-81:\d+/);
1717
expect(layers[1]).to.match(/arn:aws:lambda:us-east-1:534081306603:layer:console:\d+/);
1818
});
19+
20+
// https://github.com/brefphp/constructs/issues/1
21+
it('can build multiple functions in the same stack', () => {
22+
const template = compileTestStack((stack) => {
23+
new ConsoleFunction(stack, 'Function1', {
24+
handler: 'index.php',
25+
});
26+
new ConsoleFunction(stack, 'Function2', {
27+
handler: 'index.php',
28+
});
29+
});
30+
31+
template.resourceCountIs('AWS::Lambda::Function', 2);
32+
});
1933
});

test/function/PhpFpmFunction.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ import { cleanupTemplate, compileTestStack } from '../helper';
55
describe('PhpFpmFunction', () => {
66
it('builds', () => {
77
const template = compileTestStack((stack) => {
8-
new PhpFpmFunction(stack, 'Function', {
9-
handler: 'index.php',
10-
});
8+
new PhpFpmFunction(stack, 'Function');
119
}).toJSON();
1210

1311
expect(cleanupTemplate(template).Resources).toMatchSnapshot();
1412
});
13+
14+
// https://github.com/brefphp/constructs/issues/1
15+
it('can build multiple functions in the same stack', () => {
16+
const template = compileTestStack((stack) => {
17+
new PhpFpmFunction(stack, 'Function1');
18+
new PhpFpmFunction(stack, 'Function2');
19+
});
20+
21+
template.resourceCountIs('AWS::Lambda::Function', 2);
22+
});
1523
});

test/function/PhpFunction.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ describe('PhpFunction', () => {
1212

1313
expect(cleanupTemplate(template).Resources).toMatchSnapshot();
1414
});
15+
16+
// https://github.com/brefphp/constructs/issues/1
17+
it('can build multiple functions in the same stack', () => {
18+
const template = compileTestStack((stack) => {
19+
new PhpFunction(stack, 'Function1', {
20+
handler: 'index.php',
21+
});
22+
new PhpFunction(stack, 'Function2', {
23+
handler: 'index.php',
24+
});
25+
});
26+
27+
template.resourceCountIs('AWS::Lambda::Function', 2);
28+
});
1529
});

0 commit comments

Comments
 (0)