Skip to content

Commit

Permalink
polish pr
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jan 20, 2025
1 parent 9a9d135 commit 7969258
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 92 deletions.
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"pest_2.36.0","defects":[],"times":{"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\AskToRunMigrationsTest::__pest_evaluable_it_can_ask_to_run_the_migrations":0.042,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\AssetsTest::__pest_evaluable_it_can_install_the_assets":0.009,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\ConfigFileTest::__pest_evaluable_it_can_install_the_config_file":0.001,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\CopyAndRegisterServiceProviderInAppTest::__pest_evaluable_it_can_copy_and_register_the_service_provider_in_the_app":0.003,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\EndWithTest::__pest_evaluable_it_can_execute_the_end_with":0.001,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\MigrationTest::__pest_evaluable_it_can_install_the_migrations":0.002,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\StarRepoTest::__pest_evaluable_it_can_propose_to_star_the_repo":0.001,"P\\Tests\\PackageServiceProviderTests\\InstallCommandTests\\StartWithTest::__pest_evaluable_it_can_execute_the_start_with":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageAssetsTest::__pest_evaluable_it_can_publish_the_assets":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageCommandTest::__pest_evaluable_it_can_execute_a_registered_commands":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageCommandWithinAppTest::__pest_evaluable_it_can_execute_a_registered_command_in_the_context_of_the_app":0.011,"P\\Tests\\PackageServiceProviderTests\\PackageCommandsTest::__pest_evaluable_it_can_execute_a_registered_commands":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageConfigTest::__pest_evaluable_it_can_register_the_config_file":0,"P\\Tests\\PackageServiceProviderTests\\PackageConfigTest::__pest_evaluable_it_can_publish_the_config_file":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageDiscoversMigrationsTest::__pest_evaluable_it_publishes_discovered_migrations":0.003,"P\\Tests\\PackageServiceProviderTests\\PackageDiscoversMigrationsTest::__pest_evaluable_it_can_publish_the_migration_without_being_stubbed":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageDiscoversMigrationsTest::__pest_evaluable_it_does_not_overwrite_the_existing_migration":0.004,"P\\Tests\\PackageServiceProviderTests\\PackageDiscoversMigrationsTest::__pest_evaluable_it_can_run_migrations_which_registers_them":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageMigrationTest::__pest_evaluable_it_can_publish_the_migration":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageMigrationTest::__pest_evaluable_it_can_publish_the_migration_without_being_stubbed":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageMigrationTest::__pest_evaluable_it_does_not_overwrite_the_existing_migration":0.003,"P\\Tests\\PackageServiceProviderTests\\PackageMigrationTest::__pest_evaluable_it_does_overwrite_the_existing_migration_with_force":0.003,"P\\Tests\\PackageServiceProviderTests\\PackageMigrationTest::__pest_evaluable_it_can_run_migrations_which_registers_them":0,"P\\Tests\\PackageServiceProviderTests\\PackageMultipleConfigTest::__pest_evaluable_it_can_register_multiple_config_files":0,"P\\Tests\\PackageServiceProviderTests\\PackageNameTest::__pest_evaluable_it_will_not_blow_up_when_a_name_is_set":0,"P\\Tests\\PackageServiceProviderTests\\PackagePublishableProviderTest::__pest_evaluable_it_can_publish_a_service_provider":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageRouteTest::__pest_evaluable_it_can_load_the_route":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageRouteTest::__pest_evaluable_it_can_load_multiple_route":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageRoutesTest::__pest_evaluable_it_can_load_the_route":0,"P\\Tests\\PackageServiceProviderTests\\PackageRoutesTest::__pest_evaluable_it_can_load_multiple_route":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageSharedDataTest::__pest_evaluable_it_can_share_data_with_all_views":0.005,"P\\Tests\\PackageServiceProviderTests\\PackageTranslationsTest::__pest_evaluable_it_can_load_the_translations":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageTranslationsTest::__pest_evaluable_it_can_publish_the_translations":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageViewComponentsTest::__pest_evaluable_it_can_load_the_view_components":0.002,"P\\Tests\\PackageServiceProviderTests\\PackageViewComponentsTest::__pest_evaluable_it_can_publish_the_view_components":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageViewComposerTest::__pest_evaluable_it_can_load_the_view_composer_and_render_shared_data":0,"P\\Tests\\PackageServiceProviderTests\\PackageViewsTest::__pest_evaluable_it_can_load_the_views":0,"P\\Tests\\PackageServiceProviderTests\\PackageViewsTest::__pest_evaluable_it_can_publish_the_views":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageViewsWithCustomNamespaceTest::__pest_evaluable_it_can_load_the_views_with_a_custom_namespace":0.001,"P\\Tests\\PackageServiceProviderTests\\PackageViewsWithCustomNamespaceTest::__pest_evaluable_it_can_publish_the_views_with_a_custom_namespace":0.001}}
43 changes: 14 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
33 changes: 0 additions & 33 deletions src/Actions/GenerateMigrationName.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasAssets
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasCommands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasConfigs
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasConsoleCommands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasInertia
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

use Spatie\LaravelPackageTools\Commands\InstallCommand;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasMigrations
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasProviders
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasRoutes
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasTranslations
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasViewComponents
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasViewComposers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasViewSharedData
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Spatie\LaravelPackageTools\Traits;
namespace Spatie\LaravelPackageTools\Concerns\Package;

trait HasViews
{
Expand Down
28 changes: 14 additions & 14 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
namespace Spatie\LaravelPackageTools;

use Illuminate\Support\Str;
use Spatie\LaravelPackageTools\Traits\HasAssets;
use Spatie\LaravelPackageTools\Traits\HasCommands;
use Spatie\LaravelPackageTools\Traits\HasConfigs;
use Spatie\LaravelPackageTools\Traits\HasConsoleCommands;
use Spatie\LaravelPackageTools\Traits\HasInertia;
use Spatie\LaravelPackageTools\Traits\HasInstallCommand;
use Spatie\LaravelPackageTools\Traits\HasMigrations;
use Spatie\LaravelPackageTools\Traits\HasProviders;
use Spatie\LaravelPackageTools\Traits\HasRoutes;
use Spatie\LaravelPackageTools\Traits\HasTranslations;
use Spatie\LaravelPackageTools\Traits\HasViewComponents;
use Spatie\LaravelPackageTools\Traits\HasViewComposers;
use Spatie\LaravelPackageTools\Traits\HasViews;
use Spatie\LaravelPackageTools\Traits\HasViewSharedData;
use Spatie\LaravelPackageTools\Concerns\Package\HasAssets;
use Spatie\LaravelPackageTools\Concerns\Package\HasCommands;
use Spatie\LaravelPackageTools\Concerns\Package\HasConfigs;
use Spatie\LaravelPackageTools\Concerns\Package\HasConsoleCommands;
use Spatie\LaravelPackageTools\Concerns\Package\HasInertia;
use Spatie\LaravelPackageTools\Concerns\Package\HasInstallCommand;
use Spatie\LaravelPackageTools\Concerns\Package\HasMigrations;
use Spatie\LaravelPackageTools\Concerns\Package\HasProviders;
use Spatie\LaravelPackageTools\Concerns\Package\HasRoutes;
use Spatie\LaravelPackageTools\Concerns\Package\HasTranslations;
use Spatie\LaravelPackageTools\Concerns\Package\HasViewComponents;
use Spatie\LaravelPackageTools\Concerns\Package\HasViewComposers;
use Spatie\LaravelPackageTools\Concerns\Package\HasViews;
use Spatie\LaravelPackageTools\Concerns\Package\HasViewSharedData;

class Package
{
Expand Down
28 changes: 26 additions & 2 deletions src/PackageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected function bootMigrations(): void

foreach ($this->package->migrationFileNames as $migrationFileName) {
$vendorMigration = $this->package->basePath("/../database/migrations/{$migrationFileName}.php");
$appMigration = GenerateMigrationName::execute($migrationFileName, $now->addSecond());
$appMigration = $this->generateMigrationName($migrationFileName, $now->addSecond());

// Support for the .stub file extension
if (! file_exists($vendorMigration)) {
Expand Down Expand Up @@ -314,7 +314,7 @@ protected function discoverMigrations(): void
$filePath = $file->getPathname();
$migrationFileName = Str::replace(['.stub', '.php'], '', $file->getFilename());

$appMigration = GenerateMigrationName::execute($migrationFileName, $now->addSecond());
$appMigration = $this->generateMigrationName($migrationFileName, $now->addSecond());

if ($this->app->runningInConsole()) {
$this->publishes(
Expand All @@ -328,4 +328,28 @@ protected function discoverMigrations(): void
}
}
}

protected function generateMigrationName(string $migrationFileName, Carbon $now): string
{
$migrationsPath = 'migrations/'.dirname($migrationFileName).'/';
$migrationFileName = basename($migrationFileName);

$len = strlen($migrationFileName) + 4;

if (Str::contains($migrationFileName, '/')) {
$migrationsPath .= Str::of($migrationFileName)->beforeLast('/')->finish('/');
$migrationFileName = Str::of($migrationFileName)->afterLast('/');
}

foreach (glob(database_path("{$migrationsPath}*.php")) as $filename) {
if ((substr($filename, -$len) === $migrationFileName.'.php')) {
return $filename;
}
}

$timestamp = $now->format('Y_m_d_His');
$migrationFileName = Str::of($migrationFileName)->snake()->finish('.php');

return database_path($migrationsPath.$timestamp.'_'.$migrationFileName);
}
}

0 comments on commit 7969258

Please sign in to comment.