Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Update upgrade.sh to work with extracted Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Nov 30, 2021
1 parent 9bc18df commit 9964e37
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@
/phpunit.xml.dist export-ignore
/readme.md export-ignore
/upgrade.sh export-ignore
/tests/files/Support/Carbon.php export-ignore
/tests/files/Support/HtmlString.php export-ignore
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"tests/files/Support/HtmlString.php",
"tests/files/Support/HigherOrderTapProxy.php",
"tests/files/Support/Str.php",
"tests/files/Support/Stringable.php"
"tests/files/Support/Traits/Conditionable.php",
"tests/files/Support/Stringable.php",
"tests/files/Support/ItemNotFoundException.php",
"tests/files/Support/MultipleItemsFoundException.php",
"tests/Support/Concerns/CountsEnumerations.php"
]
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions stubs/src/Collect/Support/alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

$aliases = [/*--- ALIASES ---*/];

# echo "\n\n-- Aliasing....\n---------------------------------------------\n\n";

foreach ($aliases as $tighten => $illuminate) {
if (! class_exists($illuminate) && ! interface_exists($illuminate) && ! trait_exists($illuminate)) {
# echo "Aliasing {$tighten} to {$illuminate}.\n";
class_alias($tighten, $illuminate);
}
}
15 changes: 15 additions & 0 deletions stubs/src/Collect/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,19 @@ function dd(...$args)
die(1);
}
}

if (! function_exists('class_basename')) {
/**
* Get the class "basename" of the given object / class.
*
* @param string|object $class
* @return string
*/
function class_basename($class)
{
$class = is_object($class) ? get_class($class) : $class;

return basename(str_replace('\\', '/', $class));
}
}
}
26 changes: 26 additions & 0 deletions upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ carriageReturn="
'Contracts/Support/Arrayable'
'Contracts/Support/Jsonable'
'Contracts/Support/Htmlable'
'Contracts/Support/CanBeEscapedWhenCastToString'
)

tests=(
Expand All @@ -142,6 +143,7 @@ carriageReturn="
'Support/SupportMacroableTest.php'
'Support/SupportLazyCollectionTest.php'
'Support/SupportLazyCollectionIsLazyTest.php'
'Support/Concerns/CountsEnumerations.php'
)

testSupportClasses=(
Expand All @@ -150,6 +152,12 @@ carriageReturn="
'Support/HtmlString'
'Support/Str'
'Support/Stringable'
'Support/Traits/Conditionable'
)

testSupportClassesInExtractedCollections=(
'Support/ItemNotFoundException'
'Support/MultipleItemsFoundException'
)

stubs=(
Expand Down Expand Up @@ -395,6 +403,22 @@ function copyTestSupportClasses()
chmod 644 ${testSupportDirectory}/${class}.php
done

for class in ${testSupportClassesInExtractedCollections[@]}; do
echo "Copying ${oldNamespaceDir}/${class} (from extracted Collections)..."

mkdir -p $(dirname $testSupportDirectory/$class)

# Extract these classes from Illuminate/Collections, even though they end up in
# the Illuminate/Support namespace
movedClassFilename=${class/Support/Collections}

cp ${oldNamespaceDir}/${movedClassFilename}.php ${testSupportDirectory}/$class.php

chmod 644 ${testSupportDirectory}/${class}.php
done

testSupportClassesInExtractedCollections

# @todo: do this more cleanly
find ./tests/files -name "*.php" -exec sed -i "" -e "s|Illuminate\\\Support|/\*--- OLDNAMESPACE ---\*/\\\Support|g" {} \;
}
Expand Down Expand Up @@ -426,6 +450,8 @@ function renameNamespace()
find ${testsDir} -name "*.php" -exec sed -i "" -e "s|Illuminate\\\Support\\\Traits\\\Tappable|Tightenco\\\Collect\\\Support\\\Traits\\\Tappable|g" {} \;

find ${testSupportDirectory} -name "HigherOrderTapProxy.php" -exec sed -i "" -e "s|Illuminate\\\Support|Tightenco\\\Collect\\\Support|g" {} \;
find ${testSupportDirectory} -name "ItemNotFoundException.php" -exec sed -i "" -e "s|Illuminate\\\Support|Tightenco\\\Collect\\\Support|g" {} \;
find ${testSupportDirectory} -name "MultipleItemsFoundException.php" -exec sed -i "" -e "s|Illuminate\\\Support|Tightenco\\\Collect\\\Support|g" {} \;
}

##
Expand Down

0 comments on commit 9964e37

Please sign in to comment.