Skip to content

Commit

Permalink
Merge pull request #619 from lhsazevedo/entrypoint-namespace
Browse files Browse the repository at this point in the history
Do not create the entrypoint when namespace isn't set
  • Loading branch information
Chemaclass committed Oct 5, 2023
2 parents f530dbb + 98a2857 commit 1036432
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/php/Build/BuildFactory.php
Expand Up @@ -35,6 +35,7 @@ public function createProjectCompiler(): ProjectCompiler
$this->getCommandFacade(),
$this->createMainPhpEntryPointFile(),
$this->getConfig()->getPathsToIgnore(),
$this->getConfig()->getPhelOutConfig()->shouldCreateEntryPointPhpFile(),
);
}

Expand Down
5 changes: 4 additions & 1 deletion src/php/Build/Domain/Compile/ProjectCompiler.php
Expand Up @@ -27,6 +27,7 @@ public function __construct(
private CommandFacadeInterface $commandFacade,
private EntryPointPhpFileInterface $entryPointPhpFile,
private array $pathsToIgnore,
private bool $shouldCreateEntryPointPhpFile,
) {
}

Expand Down Expand Up @@ -81,7 +82,9 @@ private function compileFromTo(array $srcDirectories, string $dest, BuildOptions
touch($targetFile, filemtime($info->getFile()));
}

$this->entryPointPhpFile->createFile();
if ($this->shouldCreateEntryPointPhpFile) {
$this->entryPointPhpFile->createFile();
}

return $result;
}
Expand Down
5 changes: 5 additions & 0 deletions src/php/Config/PhelOutConfig.php
Expand Up @@ -66,6 +66,11 @@ public function setMainPhpFilename(string $name): self
return $this;
}

public function shouldCreateEntryPointPhpFile(): bool
{
return (bool) $this->getMainPhelNamespace();
}

public function jsonSerialize(): array
{
return [
Expand Down
43 changes: 38 additions & 5 deletions tests/php/Integration/Build/Command/BuildCommandTest.php
Expand Up @@ -15,11 +15,6 @@ final class BuildCommandTest extends TestCase
{
private BuildCommand $command;

public static function setUpBeforeClass(): void
{
Gacela::bootstrap(__DIR__, GacelaConfig::defaultPhpConfig());
}

protected function setUp(): void
{
$this->command = new BuildCommand();
Expand All @@ -32,6 +27,10 @@ protected function setUp(): void
*/
public function test_build_project(): void
{
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
$config->addAppConfig('config/phel-config.php');
});

$this->expectOutputString("This is printed\n");

$this->command->run(
Expand All @@ -57,6 +56,10 @@ public function test_build_project(): void
*/
public function test_build_project_cached(): void
{
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
$config->addAppConfig('config/phel-config.php');
});

// Mark file cache invalid by setting the modification time to 0
touch(__DIR__ . '/out/test_ns/hello.php', 1);

Expand All @@ -82,6 +85,10 @@ public function test_build_project_cached(): void
*/
public function test_out_main_file(): void
{
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
$config->addAppConfig('config/phel-config.php');
});

$this->command->run(
new ArrayInput([
'--no-source-map' => true,
Expand All @@ -102,4 +109,30 @@ public function test_out_main_file(): void
TXT;
self::assertSame($expected, $actual);
}

/**
* @runInSeparateProcess
*
* @preserveGlobalState disabled
*/
public function test_no_entrypoint_when_namespace_is_not_set(): void
{
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
$config->addAppConfig('config/phel-config-no-namespace.php');
});

if (file_exists(__DIR__ . '/out/main.php')) {
unlink(__DIR__ . '/out/main.php');
}

$this->command->run(
new ArrayInput([
'--no-source-map' => true,
'--no-cache' => true,
]),
$this->createStub(OutputInterface::class),
);

$this->assertFileDoesNotExist(__DIR__ . '/out/main.php');
}
}
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Phel\Config\PhelOutConfig;

return (new \Phel\Config\PhelConfig())
->setSrcDirs(['../../../../../src/phel/', 'src'])
->setVendorDir('')
->setOut((new PhelOutConfig())
->setDestDir('out'))
->setIgnoreWhenBuilding(['local.phel', 'failing.phel'])
;

0 comments on commit 1036432

Please sign in to comment.