From c1ff06071b3179d9eb3d594718db78655b73b47d Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 09:54:44 +0200 Subject: [PATCH 01/15] Running conf script --- .github/FUNDING.yml | 2 +- .github/ISSUE_TEMPLATE/config.yml | 6 +- CHANGELOG.md | 2 +- LICENSE.md | 2 +- README.md | 35 +- composer.json | 27 +- config/bokio-api-laravel.php | 6 + config/skeleton.php | 6 - configure.php | 370 ------------------ database/factories/ModelFactory.php | 19 - .../migrations/create_skeleton_table.php.stub | 19 - phpunit.xml.dist | 2 +- resources/views/.gitkeep | 0 src/BokioApiLaravel.php | 5 + ...php => BokioApiLaravelServiceProvider.php} | 12 +- ...Command.php => BokioApiLaravelCommand.php} | 6 +- src/Facades/BokioApiLaravel.php | 16 + src/Facades/Skeleton.php | 16 - src/Skeleton.php | 5 - tests/Pest.php | 2 +- tests/TestCase.php | 8 +- 21 files changed, 75 insertions(+), 491 deletions(-) create mode 100644 config/bokio-api-laravel.php delete mode 100644 config/skeleton.php delete mode 100644 configure.php delete mode 100644 database/factories/ModelFactory.php delete mode 100644 database/migrations/create_skeleton_table.php.stub delete mode 100644 resources/views/.gitkeep create mode 100755 src/BokioApiLaravel.php rename src/{SkeletonServiceProvider.php => BokioApiLaravelServiceProvider.php} (55%) rename src/Commands/{SkeletonCommand.php => BokioApiLaravelCommand.php} (59%) create mode 100644 src/Facades/BokioApiLaravel.php delete mode 100644 src/Facades/Skeleton.php delete mode 100755 src/Skeleton.php diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index c68765b..9e5cabb 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -github: :vendor_name +github: Mattitja AB diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 6474295..f34672a 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,11 +1,11 @@ blank_issues_enabled: false contact_links: - name: Ask a question - url: https://github.com/:vendor_slug/:package_name/discussions/new?category=q-a + url: https://github.com/mattitjaab/bokio-api-laravel/discussions/new?category=q-a about: Ask the community for help - name: Request a feature - url: https://github.com/:vendor_slug/:package_name/discussions/new?category=ideas + url: https://github.com/mattitjaab/bokio-api-laravel/discussions/new?category=ideas about: Share ideas for new features - name: Report a security issue - url: https://github.com/:vendor_slug/:package_name/security/policy + url: https://github.com/mattitjaab/bokio-api-laravel/security/policy about: Learn how to notify us for sensitive bugs diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b3242..abbf707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -All notable changes to `:package_name` will be documented in this file. +All notable changes to `bokio-api-laravel` will be documented in this file. diff --git a/LICENSE.md b/LICENSE.md index 58c9ad4..e90c3f2 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) :vendor_name +Copyright (c) Mattitja AB Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 375da96..675e951 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,15 @@ -# :package_description +# A Laravel wrapper for the Bokio API -[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) -[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain) -[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) -[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) - ---- -This repo can be used to scaffold a Laravel package. Follow these steps to get started: +[![Latest Version on Packagist](https://img.shields.io/packagist/v/mattitjaab/bokio-api-laravel.svg?style=flat-square)](https://packagist.org/packages/mattitjaab/bokio-api-laravel) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/mattitjaab/bokio-api-laravel/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mattitjaab/bokio-api-laravel/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/mattitjaab/bokio-api-laravel/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/mattitjaab/bokio-api-laravel/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/mattitjaab/bokio-api-laravel.svg?style=flat-square)](https://packagist.org/packages/mattitjaab/bokio-api-laravel) -1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton. -2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files. -3. Have fun creating your package. -4. If you need help creating a package, consider picking up our Laravel Package Training video course. ---- - This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. ## Support us -[](https://spatie.be/github-ad-click/:package_name) +[](https://spatie.be/github-ad-click/bokio-api-laravel) We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). @@ -29,20 +20,20 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh You can install the package via composer: ```bash -composer require :vendor_slug/:package_slug +composer require mattitjaab/bokio-api-laravel ``` You can publish and run the migrations with: ```bash -php artisan vendor:publish --tag=":package_slug-migrations" +php artisan vendor:publish --tag="bokio-api-laravel-migrations" php artisan migrate ``` You can publish the config file with: ```bash -php artisan vendor:publish --tag=":package_slug-config" +php artisan vendor:publish --tag="bokio-api-laravel-config" ``` This is the contents of the published config file: @@ -55,14 +46,14 @@ return [ Optionally, you can publish the views using ```bash -php artisan vendor:publish --tag=":package_slug-views" +php artisan vendor:publish --tag="bokio-api-laravel-views" ``` ## Usage ```php -$variable = new VendorName\Skeleton(); -echo $variable->echoPhrase('Hello, VendorName!'); +$bokioApiLaravel = new Mattitja\BokioApiLaravel(); +echo $bokioApiLaravel->echoPhrase('Hello, Mattitja!'); ``` ## Testing @@ -85,7 +76,7 @@ Please review [our security policy](../../security/policy) on how to report secu ## Credits -- [:author_name](https://github.com/:author_username) +- [Mattitja AB](https://github.com/MattitjaAB) - [All Contributors](../../contributors) ## License diff --git a/composer.json b/composer.json index 8f9b850..f90f44b 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,24 @@ { - "name": ":vendor_slug/:package_slug", - "description": ":package_description", + "name": "mattitjaab/bokio-api-laravel", + "description": "A Laravel wrapper for the Bokio API", "keywords": [ - ":vendor_name", + "Mattitja AB", + "Mattitja", + "MattitjaAB", "laravel", - ":package_slug" + "bokio-api-laravel" ], - "homepage": "https://github.com/:vendor_slug/:package_slug", + "homepage": "https://github.com/mattitjaab/bokio-api-laravel", "license": "MIT", "authors": [ { - "name": ":author_name", - "email": "author@domain.com", + "name": "Mattitja AB", + "email": "hej@mattitja.se", "role": "Developer" } ], "require": { - "php": "^8.4", + "php": "^8.3", "spatie/laravel-package-tools": "^1.16", "illuminate/contracts": "^10.0||^11.0||^12.0" }, @@ -35,13 +37,12 @@ }, "autoload": { "psr-4": { - "VendorName\\Skeleton\\": "src/", - "VendorName\\Skeleton\\Database\\Factories\\": "database/factories/" + "Mattitja\\BokioApiLaravel\\": "src/" } }, "autoload-dev": { "psr-4": { - "VendorName\\Skeleton\\Tests\\": "tests/", + "Mattitja\\BokioApiLaravel\\Tests\\": "tests/", "Workbench\\App\\": "workbench/app/" } }, @@ -63,10 +64,10 @@ "extra": { "laravel": { "providers": [ - "VendorName\\Skeleton\\SkeletonServiceProvider" + "Mattitja\\BokioApiLaravel\\BokioApiLaravelServiceProvider" ], "aliases": { - "Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton" + "BokioApiLaravel": "Mattitja\\BokioApiLaravel\\Facades\\BokioApiLaravel" } } }, diff --git a/config/bokio-api-laravel.php b/config/bokio-api-laravel.php new file mode 100644 index 0000000..b890cb6 --- /dev/null +++ b/config/bokio-api-laravel.php @@ -0,0 +1,6 @@ + $version) { - if (in_array($name, $names, true)) { - unset($data['require-dev'][$name]); - } - } - - file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); -} - -function remove_composer_script($scriptName) -{ - $data = json_decode(file_get_contents(__DIR__.'/composer.json'), true); - - foreach ($data['scripts'] as $name => $script) { - if ($scriptName === $name) { - unset($data['scripts'][$name]); - break; - } - } - - file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); -} - -function remove_readme_paragraphs(string $file): void -{ - $contents = file_get_contents($file); - - file_put_contents( - $file, - preg_replace('/.*/s', '', $contents) ?: $contents - ); -} - -function safeUnlink(string $filename) -{ - if (file_exists($filename) && is_file($filename)) { - unlink($filename); - } -} - -function determineSeparator(string $path): string -{ - return str_replace('/', DIRECTORY_SEPARATOR, $path); -} - -function replaceForWindows(): array -{ - return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":author :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com"')); -} - -function replaceForAllOtherOSes(): array -{ - return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__))); -} - -function getGitHubApiEndpoint(string $endpoint): ?stdClass -{ - try { - $curl = curl_init("https://api.github.com/{$endpoint}"); - curl_setopt_array($curl, [ - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_HTTPGET => true, - CURLOPT_HTTPHEADER => [ - 'User-Agent: spatie-configure-script/1.0', - ], - ]); - - $response = curl_exec($curl); - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); - - curl_close($curl); - - if ($statusCode === 200) { - return json_decode($response); - } - } catch (Exception $e) { - // ignore - } - - return null; -} - -function searchCommitsForGitHubUsername(): string -{ - $authorName = strtolower(trim(shell_exec('git config user.name'))); - - $committersRaw = shell_exec("git log --author='@users.noreply.github.com' --pretty='%an:%ae' --reverse"); - $committersLines = explode("\n", $committersRaw ?? ''); - $committers = array_filter(array_map(function ($line) use ($authorName) { - $line = trim($line); - [$name, $email] = explode(':', $line) + [null, null]; - - return [ - 'name' => $name, - 'email' => $email, - 'isMatch' => strtolower($name) === $authorName && ! str_contains($name, '[bot]'), - ]; - }, $committersLines), fn ($item) => $item['isMatch']); - - if (empty($committers)) { - return ''; - } - - $firstCommitter = reset($committers); - - return explode('@', $firstCommitter['email'])[0] ?? ''; -} - -function guessGitHubUsernameUsingCli() -{ - try { - if (preg_match('/ogged in to github\.com as ([a-zA-Z-_]+).+/', shell_exec('gh auth status -h github.com 2>&1'), $matches)) { - return $matches[1]; - } - } catch (Exception $e) { - // ignore - } - - return ''; -} - -function guessGitHubUsername(): string -{ - $username = searchCommitsForGitHubUsername(); - if (! empty($username)) { - return $username; - } - - $username = guessGitHubUsernameUsingCli(); - if (! empty($username)) { - return $username; - } - - // fall back to using the username from the git remote - $remoteUrl = shell_exec('git config remote.origin.url') ?? ''; - $remoteUrlParts = explode('/', str_replace(':', '/', trim($remoteUrl))); - - return $remoteUrlParts[1] ?? ''; -} - -function guessGitHubVendorInfo($authorName, $username): array -{ - $remoteUrl = shell_exec('git config remote.origin.url') ?? ''; - $remoteUrlParts = explode('/', str_replace(':', '/', trim($remoteUrl))); - - if (! isset($remoteUrlParts[1])) { - return [$authorName, $username]; - } - - $response = getGitHubApiEndpoint("orgs/{$remoteUrlParts[1]}"); - - if ($response === null) { - return [$authorName, $username]; - } - - return [$response->name ?? $authorName, $response->login ?? $username]; -} - -$gitName = run('git config user.name'); -$authorName = ask('Author name', $gitName); - -$gitEmail = run('git config user.email'); -$authorEmail = ask('Author email', $gitEmail); -$authorUsername = ask('Author username', guessGitHubUsername()); - -$guessGitHubVendorInfo = guessGitHubVendorInfo($authorName, $authorUsername); - -$vendorName = ask('Vendor name', $guessGitHubVendorInfo[0]); -$vendorUsername = ask('Vendor username', $guessGitHubVendorInfo[1] ?? slugify($vendorName)); -$vendorSlug = slugify($vendorUsername); - -$vendorNamespace = str_replace('-', '', ucwords($vendorName)); -$vendorNamespace = ask('Vendor namespace', $vendorNamespace); - -$currentDirectory = getcwd(); -$folderName = basename($currentDirectory); - -$packageName = ask('Package name', $folderName); -$packageSlug = slugify($packageName); -$packageSlugWithoutPrefix = remove_prefix('laravel-', $packageSlug); - -$className = title_case($packageName); -$className = ask('Class name', $className); -$variableName = lcfirst($className); -$description = ask('Package description', "This is my package {$packageSlug}"); - -$usePhpStan = confirm('Enable PhpStan?', true); -$useLaravelPint = confirm('Enable Laravel Pint?', true); -$useDependabot = confirm('Enable Dependabot?', true); -$useLaravelRay = confirm('Use Ray for debugging?', true); -$useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true); - -writeln('------'); -writeln("Author : {$authorName} ({$authorUsername}, {$authorEmail})"); -writeln("Vendor : {$vendorName} ({$vendorSlug})"); -writeln("Package : {$packageSlug} <{$description}>"); -writeln("Namespace : {$vendorNamespace}\\{$className}"); -writeln("Class name : {$className}"); -writeln('---'); -writeln('Packages & Utilities'); -writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no')); -writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no')); -writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no')); -writeln('Use Ray App : '.($useLaravelRay ? 'yes' : 'no')); -writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no')); -writeln('------'); - -writeln('This script will replace the above values in all relevant files in the project directory.'); - -if (! confirm('Modify files?', true)) { - exit(1); -} - -$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); - -foreach ($files as $file) { - replace_in_file($file, [ - ':author_name' => $authorName, - ':author_username' => $authorUsername, - 'author@domain.com' => $authorEmail, - ':vendor_name' => $vendorName, - ':vendor_slug' => $vendorSlug, - 'VendorName' => $vendorNamespace, - ':package_name' => $packageName, - ':package_slug' => $packageSlug, - ':package_slug_without_prefix' => $packageSlugWithoutPrefix, - 'Skeleton' => $className, - 'skeleton' => $packageSlug, - 'migration_table_name' => title_snake($packageSlug), - 'variable' => $variableName, - ':package_description' => $description, - ]); - - match (true) { - str_contains($file, determineSeparator('src/Skeleton.php')) => rename($file, determineSeparator('./src/'.$className.'.php')), - str_contains($file, determineSeparator('src/SkeletonServiceProvider.php')) => rename($file, determineSeparator('./src/'.$className.'ServiceProvider.php')), - str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/'.$className.'.php')), - str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/'.$className.'Command.php')), - str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_'.title_snake($packageSlugWithoutPrefix).'_table.php.stub')), - str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php')), - str_contains($file, 'README.md') => remove_readme_paragraphs($file), - default => [], - }; -} - -if (! $useLaravelPint) { - safeUnlink(__DIR__.'/.github/workflows/fix-php-code-style-issues.yml'); - safeUnlink(__DIR__.'/pint.json'); -} - -if (! $usePhpStan) { - safeUnlink(__DIR__.'/phpstan.neon.dist'); - safeUnlink(__DIR__.'/phpstan-baseline.neon'); - safeUnlink(__DIR__.'/.github/workflows/phpstan.yml'); - - remove_composer_deps([ - 'phpstan/extension-installer', - 'phpstan/phpstan-deprecation-rules', - 'phpstan/phpstan-phpunit', - 'larastan/larastan', - ]); - - remove_composer_script('phpstan'); -} - -if (! $useDependabot) { - safeUnlink(__DIR__.'/.github/dependabot.yml'); - safeUnlink(__DIR__.'/.github/workflows/dependabot-auto-merge.yml'); -} - -if (! $useLaravelRay) { - remove_composer_deps(['spatie/laravel-ray']); -} - -if (! $useUpdateChangelogWorkflow) { - safeUnlink(__DIR__.'/.github/workflows/update-changelog.yml'); -} - -confirm('Execute `composer install` and run tests?') && run('composer install && composer test'); - -confirm('Let this script delete itself?', true) && unlink(__FILE__); diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php deleted file mode 100644 index c51604f..0000000 --- a/database/factories/ModelFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -id(); - - // add fields - - $table->timestamps(); - }); - } -}; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bfe434d..b058e3a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ backupStaticProperties="false" > - + tests diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/BokioApiLaravel.php b/src/BokioApiLaravel.php new file mode 100755 index 0000000..4a36193 --- /dev/null +++ b/src/BokioApiLaravel.php @@ -0,0 +1,5 @@ +name('skeleton') + ->name('bokio-api-laravel') ->hasConfigFile() ->hasViews() - ->hasMigration('create_migration_table_name_table') - ->hasCommand(SkeletonCommand::class); + ->hasMigration('create_bokio_api_laravel_table') + ->hasCommand(BokioApiLaravelCommand::class); } } diff --git a/src/Commands/SkeletonCommand.php b/src/Commands/BokioApiLaravelCommand.php similarity index 59% rename from src/Commands/SkeletonCommand.php rename to src/Commands/BokioApiLaravelCommand.php index 3e5f628..41ffc27 100644 --- a/src/Commands/SkeletonCommand.php +++ b/src/Commands/BokioApiLaravelCommand.php @@ -1,12 +1,12 @@ in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php index 220551b..842a3ed 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,10 +1,10 @@ 'VendorName\\Skeleton\\Database\\Factories\\'.class_basename($modelName).'Factory' + fn (string $modelName) => 'Mattitja\\BokioApiLaravel\\Database\\Factories\\'.class_basename($modelName).'Factory' ); } protected function getPackageProviders($app) { return [ - SkeletonServiceProvider::class, + BokioApiLaravelServiceProvider::class, ]; } -- 2.53.0 From 486988b623c881e5b8287a4939f41f22d1c14eae Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 09:55:43 +0200 Subject: [PATCH 02/15] Removed command folder --- src/Commands/BokioApiLaravelCommand.php | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/Commands/BokioApiLaravelCommand.php diff --git a/src/Commands/BokioApiLaravelCommand.php b/src/Commands/BokioApiLaravelCommand.php deleted file mode 100644 index 41ffc27..0000000 --- a/src/Commands/BokioApiLaravelCommand.php +++ /dev/null @@ -1,19 +0,0 @@ -comment('All done'); - - return self::SUCCESS; - } -} -- 2.53.0 From 2239db7ee5ba836887ba6403ac96da548158e14e Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 09:55:46 +0200 Subject: [PATCH 03/15] Update BokioApiLaravelServiceProvider.php --- src/BokioApiLaravelServiceProvider.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/BokioApiLaravelServiceProvider.php b/src/BokioApiLaravelServiceProvider.php index aec46a0..2e527b6 100644 --- a/src/BokioApiLaravelServiceProvider.php +++ b/src/BokioApiLaravelServiceProvider.php @@ -2,7 +2,6 @@ namespace Mattitja\BokioApiLaravel; -use Mattitja\BokioApiLaravel\Commands\BokioApiLaravelCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -17,9 +16,6 @@ class BokioApiLaravelServiceProvider extends PackageServiceProvider */ $package ->name('bokio-api-laravel') - ->hasConfigFile() - ->hasViews() - ->hasMigration('create_bokio_api_laravel_table') - ->hasCommand(BokioApiLaravelCommand::class); + ->hasConfigFile(); } } -- 2.53.0 From 9b83d9908170131816d7e27be542294c34561446 Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 09:57:48 +0200 Subject: [PATCH 04/15] Update run-tests.yml --- .github/workflows/run-tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index adbcbe3..22357cd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -22,16 +22,13 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] php: [8.4, 8.3] - laravel: [12.*, 11.*, 10.*] + laravel: [12.*, 11.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 12.* testbench: 10.* - laravel: 11.* testbench: 9.* - - laravel: 10.* - testbench: 8.* - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} -- 2.53.0 From 62f2bbd78fb6eefa3e7437e05d17618662f37328 Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:01:14 +0200 Subject: [PATCH 05/15] Update phpstan.neon.dist --- phpstan.neon.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ab1b4c3..4a0559d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,6 @@ parameters: paths: - src - config - - database tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true -- 2.53.0 From b715e1ba1d558bf0f5cef0a7a78a681e0139e507 Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:24:16 +0200 Subject: [PATCH 06/15] Created BokioClient --- composer.json | 4 +- config/bokio-api-laravel.php | 6 -- config/bokio.php | 7 +++ src/{BokioApiLaravel.php => Bokio.php} | 2 +- src/BokioApiLaravelServiceProvider.php | 21 ------- src/BokioClient.php | 62 +++++++++++++++++++ src/BokioServiceProvider.php | 29 +++++++++ .../{BokioApiLaravel.php => Bokio.php} | 6 +- tests/TestCase.php | 6 +- 9 files changed, 107 insertions(+), 36 deletions(-) delete mode 100644 config/bokio-api-laravel.php create mode 100644 config/bokio.php rename src/{BokioApiLaravel.php => Bokio.php} (63%) delete mode 100644 src/BokioApiLaravelServiceProvider.php create mode 100644 src/BokioClient.php create mode 100644 src/BokioServiceProvider.php rename src/Facades/{BokioApiLaravel.php => Bokio.php} (53%) diff --git a/composer.json b/composer.json index f90f44b..9fdbd74 100644 --- a/composer.json +++ b/composer.json @@ -64,10 +64,10 @@ "extra": { "laravel": { "providers": [ - "Mattitja\\BokioApiLaravel\\BokioApiLaravelServiceProvider" + "Mattitja\\BokioApiLaravel\\BokioServiceProvider" ], "aliases": { - "BokioApiLaravel": "Mattitja\\BokioApiLaravel\\Facades\\BokioApiLaravel" + "Bokio": "Mattitja\\BokioApiLaravel\\Facades\\Bokio" } } }, diff --git a/config/bokio-api-laravel.php b/config/bokio-api-laravel.php deleted file mode 100644 index b890cb6..0000000 --- a/config/bokio-api-laravel.php +++ /dev/null @@ -1,6 +0,0 @@ - env('BOKIO_TOKEN'), + 'company_id' => env('BOKIO_COMPANY_ID'), +]; diff --git a/src/BokioApiLaravel.php b/src/Bokio.php similarity index 63% rename from src/BokioApiLaravel.php rename to src/Bokio.php index 4a36193..48aff62 100755 --- a/src/BokioApiLaravel.php +++ b/src/Bokio.php @@ -2,4 +2,4 @@ namespace Mattitja\BokioApiLaravel; -class BokioApiLaravel {} +class Bokio {} diff --git a/src/BokioApiLaravelServiceProvider.php b/src/BokioApiLaravelServiceProvider.php deleted file mode 100644 index 2e527b6..0000000 --- a/src/BokioApiLaravelServiceProvider.php +++ /dev/null @@ -1,21 +0,0 @@ -name('bokio-api-laravel') - ->hasConfigFile(); - } -} diff --git a/src/BokioClient.php b/src/BokioClient.php new file mode 100644 index 0000000..85efa04 --- /dev/null +++ b/src/BokioClient.php @@ -0,0 +1,62 @@ +request = Http::acceptJson() + ->asJson() + ->withToken($this->accessToken) + ->baseUrl("{$this->baseUrl}/companies/{$this->companyId}"); + } + + public function get(string $endpoint, array $query = []): object + { + return $this->request + ->get($endpoint, $query) + ->throw() + ->object(); + } + + public function post(string $endpoint, array $data = []): object + { + return $this->request + ->post($endpoint, $data) + ->throw() + ->object(); + } + + public function put(string $endpoint, array $data = []): object + { + return $this->request + ->put($endpoint, $data) + ->throw() + ->object(); + } + + public function delete(string $endpoint): bool + { + return $this->request + ->delete($endpoint) + ->throw() + ->ok(); + } + + public function contents(string $endpoint, array $query = []): string + { + return $this->request + ->get($endpoint, $query) + ->throw() + ->body(); + } +} diff --git a/src/BokioServiceProvider.php b/src/BokioServiceProvider.php new file mode 100644 index 0000000..7b8a262 --- /dev/null +++ b/src/BokioServiceProvider.php @@ -0,0 +1,29 @@ +name('bokio-api-laravel') + ->hasConfigFile(); + } + + public function register(): void + { + parent::register(); + + $this->app->singleton(BokioClient::class, function () { + return new BokioClient( + config('bokio.token'), + config('bokio.company_id'), + config('bokio.base_url', 'https://api.bokio.se'), + ); + }); + } +} diff --git a/src/Facades/BokioApiLaravel.php b/src/Facades/Bokio.php similarity index 53% rename from src/Facades/BokioApiLaravel.php rename to src/Facades/Bokio.php index 44b163a..3319b16 100644 --- a/src/Facades/BokioApiLaravel.php +++ b/src/Facades/Bokio.php @@ -5,12 +5,12 @@ namespace Mattitja\BokioApiLaravel\Facades; use Illuminate\Support\Facades\Facade; /** - * @see \Mattitja\BokioApiLaravel\BokioApiLaravel + * @see \Mattitja\BokioApiLaravel\Bokio */ -class BokioApiLaravel extends Facade +class Bokio extends Facade { protected static function getFacadeAccessor(): string { - return \Mattitja\BokioApiLaravel\BokioApiLaravel::class; + return \Mattitja\BokioApiLaravel\Bokio::class; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 842a3ed..6975b4c 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,7 @@ namespace Mattitja\BokioApiLaravel\Tests; use Illuminate\Database\Eloquent\Factories\Factory; -use Mattitja\BokioApiLaravel\BokioApiLaravelServiceProvider; +use Mattitja\BokioApiLaravel\BokioServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; class TestCase extends Orchestra @@ -13,14 +13,14 @@ class TestCase extends Orchestra parent::setUp(); Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'Mattitja\\BokioApiLaravel\\Database\\Factories\\'.class_basename($modelName).'Factory' + fn (string $modelName) => 'Mattitja\\Bokio\\Database\\Factories\\'.class_basename($modelName).'Factory' ); } protected function getPackageProviders($app) { return [ - BokioApiLaravelServiceProvider::class, + BokioServiceProvider::class, ]; } -- 2.53.0 From b28eefb1aa86a00ea3c6073f9dc5fa61d84b475c Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:25:55 +0200 Subject: [PATCH 07/15] Update BokioServiceProvider.php --- src/BokioServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BokioServiceProvider.php b/src/BokioServiceProvider.php index 7b8a262..854baf8 100644 --- a/src/BokioServiceProvider.php +++ b/src/BokioServiceProvider.php @@ -10,7 +10,7 @@ class BokioServiceProvider extends PackageServiceProvider public function configurePackage(Package $package): void { $package - ->name('bokio-api-laravel') + ->name('bokio') ->hasConfigFile(); } -- 2.53.0 From b298baf18dd2fb0edddf2cc922cf2b5d8e810b00 Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:28:52 +0200 Subject: [PATCH 08/15] Update phpstan.neon.dist --- phpstan.neon.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4a0559d..5fb9094 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,3 +9,5 @@ parameters: tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true + excludePaths: + - %currentWorkingDirectory%/config/* -- 2.53.0 From 4a2b1b6a44551fd8d5fb91ae08b83bfe4ce8b28d Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:30:35 +0200 Subject: [PATCH 09/15] Updated config file --- config/bokio.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/config/bokio.php b/config/bokio.php index 739cb19..ff12ece 100644 --- a/config/bokio.php +++ b/config/bokio.php @@ -1,7 +1,36 @@ env('BOKIO_TOKEN'), + + /* + |-------------------------------------------------------------------------- + | Company ID + |-------------------------------------------------------------------------- + | + | You can find this in the Bokio web URL when logged into your company. + | + */ + 'company_id' => env('BOKIO_COMPANY_ID'), + + /* + |-------------------------------------------------------------------------- + | Bokio API Base URL + |-------------------------------------------------------------------------- + | + | You normally don't need to change this. + | + */ + + 'base_url' => env('BOKIO_BASE_URL', 'https://api.bokio.se'), ]; -- 2.53.0 From 410906b2cdf78e456d33b6e296b281e993fa6fce Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 10:59:53 +0200 Subject: [PATCH 10/15] Added customer all and get --- src/Bokio.php | 12 +++++++- src/BokioClient.php | 2 +- src/Resources/Customer.php | 28 +++++++++++++++++ tests/CustomerTest.php | 44 +++++++++++++++++++++++++++ tests/ExampleTest.php | 5 --- tests/Responses/Customer/all.200.json | 31 +++++++++++++++++++ tests/Responses/Customer/get.200.json | 25 +++++++++++++++ 7 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 src/Resources/Customer.php create mode 100644 tests/CustomerTest.php delete mode 100644 tests/ExampleTest.php create mode 100644 tests/Responses/Customer/all.200.json create mode 100644 tests/Responses/Customer/get.200.json diff --git a/src/Bokio.php b/src/Bokio.php index 48aff62..d3d3279 100755 --- a/src/Bokio.php +++ b/src/Bokio.php @@ -2,4 +2,14 @@ namespace Mattitja\BokioApiLaravel; -class Bokio {} +use Mattitja\BokioApiLaravel\Resources\Customer; + +class Bokio +{ + public function __construct(protected BokioClient $client) {} + + public function customers(): Customer + { + return new Customer($this->client); + } +} diff --git a/src/BokioClient.php b/src/BokioClient.php index 85efa04..220ace2 100644 --- a/src/BokioClient.php +++ b/src/BokioClient.php @@ -12,7 +12,7 @@ class BokioClient public function __construct( private string $accessToken, private string $companyId, - private string $baseUrl + private string $baseUrl = 'https://api.bokio.se' ) { $this->request = Http::acceptJson() ->asJson() diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php new file mode 100644 index 0000000..186451f --- /dev/null +++ b/src/Resources/Customer.php @@ -0,0 +1,28 @@ +client->get('customers', [ + 'page' => $page, + 'pageSize' => $pageSize, + ]); + } + + public function get(string $customerId): object + { + return $this->client->get('customers/'.$customerId); + } +} diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php new file mode 100644 index 0000000..8118bb9 --- /dev/null +++ b/tests/CustomerTest.php @@ -0,0 +1,44 @@ +method() === 'GET' && preg_match('#/customers/\w+#', $request->url())) { + return Http::response(loadFixture('Customer/get.200.json'), 200); + } + + if ($request->method() === 'GET' && str_contains($request->url(), '/customers')) { + return Http::response(loadFixture('Customer/all.200.json'), 200); + } + + // fallback + return Http::response([], 404); + }); + + $this->client = new BokioClient('fake-token', '123456'); +}); + +it('can fetch a list of customers from Bokio', function () { + $response = (new Customer($this->client))->all(); + + expect($response->items)->toHaveCount(1); + expect($response->items[0]->name)->toBe('customer 1'); +}); + +it('can fetch a single customer from Bokio', function () { + $customerId = '55c899c5-82b2-47fa-9c51-e35fc9b26443'; + $response = (new Customer($this->client))->get($customerId); + + expect($response->id)->toBe($customerId); + expect($response->name)->toBe('customer 1'); +}); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php deleted file mode 100644 index 5d36321..0000000 --- a/tests/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Responses/Customer/all.200.json b/tests/Responses/Customer/all.200.json new file mode 100644 index 0000000..0cbfad2 --- /dev/null +++ b/tests/Responses/Customer/all.200.json @@ -0,0 +1,31 @@ +{ + "totalItems": 0, + "totalPages": 0, + "currentPage": 0, + "items": [ + { + "id": "55c899c5-82b2-47fa-9c51-e35fc9b26443", + "name": "customer 1", + "type": "company", + "vatNumber": "SE1234567890", + "orgNumber": "123456-7890", + "paymentTerms": "30", + "contactsDetails": [ + { + "name": "John Doe", + "email": "john@email.com", + "phone": "0927-5631505", + "isDefault": true + } + ], + "address": { + "line1": "Älvsborgsvägen 10", + "line2": null, + "city": "Göteborg", + "postalCode": "123 45", + "country": "SE" + }, + "language": "sv" + } + ] +} diff --git a/tests/Responses/Customer/get.200.json b/tests/Responses/Customer/get.200.json new file mode 100644 index 0000000..2b34730 --- /dev/null +++ b/tests/Responses/Customer/get.200.json @@ -0,0 +1,25 @@ +{ + "id": "55c899c5-82b2-47fa-9c51-e35fc9b26443", + "name": "customer 1", + "type": "company", + "vatNumber": "SE1234567890", + "orgNumber": "123456-7890", + "paymentTerms": "30", + "contactsDetails": [ + { + "id": "240a4af0-edfd-47b1-b4ab-f30450eaac19", + "name": "John Doe", + "email": "john@email.com", + "phone": "0927-5631505", + "isDefault": true + } + ], + "address": { + "line1": "Älvsborgsvägen 10", + "line2": null, + "city": "Göteborg", + "postalCode": "123 45", + "country": "SE" + }, + "language": "sv" +} -- 2.53.0 From 27ddeeacb51f5d2e9691c1eee68ca2132684b35e Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 11:11:29 +0200 Subject: [PATCH 11/15] Make page and pagesize optional --- src/Resources/Customer.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 186451f..9827828 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -13,12 +13,19 @@ class Customer /** * Get a list of all customers. */ - public function all(int $page = 1, int $pageSize = 25): object + public function all(?int $page = null, ?int $pageSize = null): object { - return $this->client->get('customers', [ - 'page' => $page, - 'pageSize' => $pageSize, - ]); + $query = []; + + if ($page !== null) { + $query['page'] = $page; + } + + if ($pageSize !== null) { + $query['pageSize'] = $pageSize; + } + + return $this->client->get('customers', $query); } public function get(string $customerId): object -- 2.53.0 From 0802d5cac23f6d3f79dfa722f4d57d3bdbc601dc Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 11:24:20 +0200 Subject: [PATCH 12/15] Customers can now be created --- src/Resources/Customer.php | 8 +++++ src/Validation/CustomerValidator.php | 38 +++++++++++++++++++++ tests/CustomerTest.php | 43 ++++++++++++++++++++++++ tests/CustomerValidatorTest.php | 27 +++++++++++++++ tests/Responses/Customer/create.201.json | 24 +++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 src/Validation/CustomerValidator.php create mode 100644 tests/CustomerValidatorTest.php create mode 100644 tests/Responses/Customer/create.201.json diff --git a/src/Resources/Customer.php b/src/Resources/Customer.php index 9827828..f207fa0 100644 --- a/src/Resources/Customer.php +++ b/src/Resources/Customer.php @@ -3,6 +3,7 @@ namespace Mattitja\BokioApiLaravel\Resources; use Mattitja\BokioApiLaravel\BokioClient; +use Mattitja\BokioApiLaravel\Validation\CustomerValidator; class Customer { @@ -32,4 +33,11 @@ class Customer { return $this->client->get('customers/'.$customerId); } + + public function create(array $data): object + { + $validated = CustomerValidator::validate($data); + + return $this->client->post('customers', $validated); + } } diff --git a/src/Validation/CustomerValidator.php b/src/Validation/CustomerValidator.php new file mode 100644 index 0000000..7269d73 --- /dev/null +++ b/src/Validation/CustomerValidator.php @@ -0,0 +1,38 @@ + 'required|string', + 'type' => 'required|string', + 'vatNumber' => 'nullable|string', + 'orgNumber' => 'nullable|string', + 'paymentTerms' => 'nullable|string', + 'language' => 'nullable|string|in:sv,en', + 'contactsDetails' => 'nullable|array', + 'contactsDetails.*.name' => 'required_with:contactsDetails|string', + 'contactsDetails.*.email' => 'nullable|email', + 'contactsDetails.*.phone' => 'nullable|string', + 'contactsDetails.*.isDefault' => 'boolean', + 'address' => 'required|array', + 'address.line1' => 'required|string', + 'address.line2' => 'nullable|string', + 'address.city' => 'required|string', + 'address.postalCode' => 'required|string', + 'address.country' => 'required|string|size:2', + ]); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + + return $validator->validated(); + } +} diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 8118bb9..fda1f6c 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -3,6 +3,8 @@ use Illuminate\Support\Facades\Http; use Mattitja\BokioApiLaravel\BokioClient; use Mattitja\BokioApiLaravel\Resources\Customer; +use Mattitja\BokioApiLaravel\Validation\CustomerValidator; +use Illuminate\Validation\ValidationException; function loadFixture(string $path): array { @@ -21,6 +23,10 @@ beforeEach(function () { return Http::response(loadFixture('Customer/all.200.json'), 200); } + if ($request->method() === 'POST' && str_contains($request->url(), '/customers')) { + return Http::response(loadFixture('Customer/create.201.json'), 201); + } + // fallback return Http::response([], 404); }); @@ -42,3 +48,40 @@ it('can fetch a single customer from Bokio', function () { expect($response->id)->toBe($customerId); expect($response->name)->toBe('customer 1'); }); + +it('can create a customer via Bokio API', function () { + $data = [ + 'name' => 'Testbolaget AB', + 'type' => 'company', + 'vatNumber' => 'SE1234567890', + 'orgNumber' => '556677-8899', + 'paymentTerms' => '30', + 'language' => 'sv', + 'contactsDetails' => [ + [ + 'name' => 'John Doe', + 'email' => 'john@example.com', + 'phone' => '0123456789', + 'isDefault' => true, + ] + ], + 'address' => [ + 'line1' => 'Testgatan 1', + 'line2' => null, + 'city' => 'Göteborg', + 'postalCode' => '12345', + 'country' => 'SE', + ], + ]; + + $response = (new Customer($this->client))->create($data); + + expect($response->id)->toBe('generated-id'); + expect($response->name)->toBe('Testbolaget AB'); + + Http::assertSent(function ($request) use ($data) { + return $request->method() === 'POST' && + str_contains($request->url(), '/customers') && + $request['name'] === $data['name']; + }); +}); diff --git a/tests/CustomerValidatorTest.php b/tests/CustomerValidatorTest.php new file mode 100644 index 0000000..1ed1f41 --- /dev/null +++ b/tests/CustomerValidatorTest.php @@ -0,0 +1,27 @@ + 'Test AB', + 'type' => 'company', + 'address' => [ + 'line1' => 'Gata 1', + 'city' => 'Ort', + 'postalCode' => '12345', + 'country' => 'SE', + ], + ]; + + $validated = CustomerValidator::validate($data); + + expect($validated['name'])->toBe('Test AB'); +}); + +it('throws exception when required fields are missing', function () { + $this->expectException(ValidationException::class); + + CustomerValidator::validate([]); +}); diff --git a/tests/Responses/Customer/create.201.json b/tests/Responses/Customer/create.201.json new file mode 100644 index 0000000..20718e9 --- /dev/null +++ b/tests/Responses/Customer/create.201.json @@ -0,0 +1,24 @@ +{ + "id": "generated-id", + "name": "Testbolaget AB", + "type": "company", + "vatNumber": "SE1234567890", + "orgNumber": "556677-8899", + "paymentTerms": "30", + "language": "sv", + "contactsDetails": [ + { + "name": "John Doe", + "email": "john@example.com", + "phone": "0123456789", + "isDefault": true + } + ], + "address": { + "line1": "Testgatan 1", + "line2": null, + "city": "Göteborg", + "postalCode": "12345", + "country": "SE" + } +} -- 2.53.0 From a80c9e5a2fb949ac580218bf073d673f06b6641e Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 11:24:29 +0200 Subject: [PATCH 13/15] pint --- tests/CustomerTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index fda1f6c..502c4ea 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -3,8 +3,6 @@ use Illuminate\Support\Facades\Http; use Mattitja\BokioApiLaravel\BokioClient; use Mattitja\BokioApiLaravel\Resources\Customer; -use Mattitja\BokioApiLaravel\Validation\CustomerValidator; -use Illuminate\Validation\ValidationException; function loadFixture(string $path): array { @@ -63,7 +61,7 @@ it('can create a customer via Bokio API', function () { 'email' => 'john@example.com', 'phone' => '0123456789', 'isDefault' => true, - ] + ], ], 'address' => [ 'line1' => 'Testgatan 1', -- 2.53.0 From 4a0857f642ddd0eddf4f8324afa12b28f38b472a Mon Sep 17 00:00:00 2001 From: Mathias Palmqvist Date: Mon, 30 Jun 2025 11:29:29 +0200 Subject: [PATCH 14/15] Updated validation --- src/Validation/CustomerValidator.php | 2 +- tests/CustomerTest.php | 1 - tests/Responses/Customer/all.200.json | 24 ++++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Validation/CustomerValidator.php b/src/Validation/CustomerValidator.php index 7269d73..9213b3d 100644 --- a/src/Validation/CustomerValidator.php +++ b/src/Validation/CustomerValidator.php @@ -11,7 +11,7 @@ class CustomerValidator { $validator = Validator::make($data, [ 'name' => 'required|string', - 'type' => 'required|string', + 'type' => 'required|string|in:company,private', 'vatNumber' => 'nullable|string', 'orgNumber' => 'nullable|string', 'paymentTerms' => 'nullable|string', diff --git a/tests/CustomerTest.php b/tests/CustomerTest.php index 502c4ea..30c3ebe 100644 --- a/tests/CustomerTest.php +++ b/tests/CustomerTest.php @@ -35,7 +35,6 @@ beforeEach(function () { it('can fetch a list of customers from Bokio', function () { $response = (new Customer($this->client))->all(); - expect($response->items)->toHaveCount(1); expect($response->items[0]->name)->toBe('customer 1'); }); diff --git a/tests/Responses/Customer/all.200.json b/tests/Responses/Customer/all.200.json index 0cbfad2..7182f31 100644 --- a/tests/Responses/Customer/all.200.json +++ b/tests/Responses/Customer/all.200.json @@ -26,6 +26,30 @@ "country": "SE" }, "language": "sv" + }, + { + "id": "55c899c5-82b2-47fa-9c51-e35fc9b26443", + "name": "customer 2", + "type": "private", + "vatNumber": null, + "orgNumber": "123456-7890", + "paymentTerms": "30", + "contactsDetails": [ + { + "name": "John Doe", + "email": "john@email.com", + "phone": "0927-5631505", + "isDefault": true + } + ], + "address": { + "line1": "Älvsborgsvägen 10", + "line2": null, + "city": "Göteborg", + "postalCode": "123 45", + "country": "SE" + }, + "language": "sv" } ] } -- 2.53.0 From 840ef8edf8ffeee0159e9cebc07b3ea64012269b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Jun 2025 09:33:29 +0000 Subject: [PATCH 15/15] Bump stefanzweifel/git-auto-commit-action from 5 to 6 Bumps [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) from 5 to 6. - [Release notes](https://github.com/stefanzweifel/git-auto-commit-action/releases) - [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/stefanzweifel/git-auto-commit-action/compare/v5...v6) --- updated-dependencies: - dependency-name: stefanzweifel/git-auto-commit-action dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/fix-php-code-style-issues.yml | 2 +- .github/workflows/update-changelog.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 1ec8dbf..6efe75d 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -23,6 +23,6 @@ jobs: uses: aglipanci/laravel-pint-action@2.5 - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v5 + uses: stefanzweifel/git-auto-commit-action@v6 with: commit_message: Fix styling diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 39de30d..64cf6ca 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -25,7 +25,7 @@ jobs: release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v5 + uses: stefanzweifel/git-auto-commit-action@v6 with: branch: main commit_message: Update CHANGELOG -- 2.53.0