-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.x] Adding backed enum support to query builder for meta #478
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
281d3a6
Revert "Revert "Support PHPUnit 10" from 0.12.x (#475)"
srtfisher aa56273
Merge branch '1.x' into feature/phpunit-10
srtfisher 1339b4e
Fixing versions
srtfisher 9058073
Merging in 0.12.x, adding changelog for 1.x
srtfisher 7c5a107
Adding enum support to meta and query builder
srtfisher df3c509
Remove unused ref
srtfisher ccb4f98
Use only enum on the query builder
srtfisher ec3d79e
Merging in 1.x
srtfisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Helper script to convert the tests/ folder to a PSR-4 folder structure. | ||
* | ||
* Moves tests/example/sub/File.php to tests/Example/Sub/FileTest.php. Only | ||
* convert the sub-part of the path (ignore anything before and including | ||
* tests/). | ||
* | ||
* phpcs:disable | ||
*/ | ||
|
||
use Mantle\Support\Str; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
use function Mantle\Support\Helpers\str; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$finder = ( new Finder() ) | ||
->in( realpath( __DIR__ . '/../tests' ) ) | ||
->directories() | ||
->notPath( '#fixtures|__snapshots__|template-parts#' ); | ||
|
||
$base = Str::trailing_slash( realpath( __DIR__ . '/../tests/' ) ); | ||
|
||
foreach ( $finder as $dir ) { | ||
$old_dir = $dir->getRealPath(); | ||
|
||
if ( ! is_dir( $old_dir ) ) { | ||
continue; | ||
} | ||
|
||
$parts = str( $old_dir )->after( $base )->explode( '/' ); | ||
|
||
$parts = $parts->map( | ||
fn ( string $part ) => str( $part )->studly()->value(), | ||
); | ||
|
||
$new_dir = $base . $parts->implode( '/' ); | ||
|
||
dump( "Moving {$old_dir} to {$new_dir}" ); | ||
|
||
shell_exec( "git mv {$old_dir} {$old_dir}-tmp" ); | ||
shell_exec( "git mv {$old_dir}-tmp {$new_dir}" ); | ||
} | ||
|
||
echo "\nDONE!\n"; | ||
|
||
exit( 0 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
/** | ||
* Helper script to convert the tests/ package to PSR-4 coding standards. | ||
* | ||
* The eventual plan is to use this for the rest of the project when that can be | ||
* converted over. Ideally this can be a reusable command in the future. | ||
* | ||
* phpcs:disable | ||
*/ | ||
|
||
use Symfony\Component\Finder\Finder; | ||
|
||
use function Mantle\Support\Helpers\str; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$finder = ( new Finder() ) | ||
->in( realpath( __DIR__ . '/../tests' ) ) | ||
->name( '*.php' ) | ||
->notName( [ 'bootstrap.php', 'sub-example.php', 'base-example.php' ] ) | ||
->notPath( '#fixtures|__snapshots__|template-parts#' ); | ||
|
||
$index = []; | ||
$pass = true; | ||
|
||
foreach ( $finder as $file ) { | ||
$filename = str( $file->getFilename() )->lower(); | ||
|
||
if ( $filename->startsWith( 'test-' ) ) { | ||
$new_filename = $filename | ||
->after( 'test-' ) | ||
->before( '.php' ) | ||
->studly() | ||
->append( 'Test.php' ) | ||
->replace( 'Wordpress', 'WordPress' ); | ||
|
||
$old_class_name = $filename | ||
->before( '.php' ) | ||
->studlyUnderscore() | ||
->replace( 'Wordpress', 'WordPress' ); | ||
|
||
$new_class_name = $filename | ||
->after( 'test-' ) | ||
->before( '.php' ) | ||
->studly() | ||
->append( 'Test' ) | ||
->replace( 'Wordpress', 'WordPress' ); | ||
} else { | ||
foreach ( [ 'trait', 'class' ] as $type ) { | ||
if ( ! $filename->startsWith( "{$type}-" ) ) { | ||
continue; | ||
} | ||
|
||
$new_filename = $filename | ||
->after( "{$type}-" ) | ||
->before( '.php' ) | ||
->studly() | ||
->append( '.php' ) | ||
->replace( 'Wordpress', 'WordPress' ); | ||
|
||
$old_class_name = $filename | ||
->after( "{$type}-" ) | ||
->before( '.php' ) | ||
->studlyUnderscore(); | ||
|
||
$new_class_name = $filename | ||
->after( "{$type}-" ) | ||
->before( '.php' ) | ||
->studly() | ||
->replace( 'Wordpress', 'WordPress' ); | ||
} | ||
} | ||
|
||
// Check if the file contains the class. | ||
$contents = str( file_get_contents( $file->getRealPath() ) ); | ||
|
||
$type = $filename->startsWith( 'trait-' ) ? 'trait' : 'class'; | ||
|
||
if ( ! $contents->contains( "{$type} {$old_class_name->value()} ", true ) ) { | ||
echo $file->getRealPath() . ' does not contain the expected legacy ' . $type . ' ' . $old_class_name->value() . PHP_EOL; | ||
|
||
$pass = false; | ||
|
||
continue; | ||
} | ||
|
||
$index[] = [ | ||
$type, | ||
[ | ||
$file->getRealPath(), | ||
$old_class_name->value(), | ||
], | ||
[ | ||
$file->getPath() . '/' . $new_filename->value(), | ||
$new_class_name->value(), | ||
], | ||
]; | ||
} | ||
|
||
if ( ! $pass ) { | ||
echo "\n\nPlease fix the above errors before continuing.\n"; | ||
|
||
exit( 1 ); | ||
} | ||
|
||
echo 'Processing ' . count( $index ) . ' files...'; | ||
|
||
foreach ( $index as $item ) { | ||
[ $type, $old, $new ] = $item; | ||
|
||
[ $old_file, $old_class ] = $old; | ||
[ $new_file, $new_class ] = $new; | ||
|
||
// Update the file with the new class name. | ||
file_put_contents( | ||
$old_file, | ||
str( file_get_contents( $old_file ) )->replace( "{$type} {$old_class} ", "{$type} {$new_class} ", false )->value(), | ||
); | ||
|
||
// Update the file name. | ||
if ( ! rename( $old_file, $new_file ) ) { | ||
echo "Failed to rename {$old_file} to {$new_file}.\n"; | ||
|
||
exit( 1 ); | ||
} | ||
|
||
echo "Updated {$old_file} to {$new_file} ({$old_class} to {$new_class}).\n"; | ||
} | ||
|
||
echo "\nDONE!\n"; | ||
|
||
exit( 0 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<phpunit | ||
bootstrap="tests/bootstrap.php" | ||
backupGlobals="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
bootstrap="tests/bootstrap.php" | ||
backupGlobals="false" | ||
colors="true" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" | ||
> | ||
<testsuites> | ||
<testsuite name="mantle-framework"> | ||
<directory prefix="test-" suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<testsuites> | ||
<testsuite name="mantle-framework"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! I didn't know about
BackedEnum