Skip to content

Instantly share code, notes, and snippets.

View ronssij's full-sized avatar
🏠
Secretly deleting database 👿

CJ Ronxel ronssij

🏠
Secretly deleting database 👿
View GitHub Profile

Test File Organization

When creating feature tests for controllers, organize test files by controller method, not by controller.

Convention

For a controller at app/Http/Controllers/{Path}/{ControllerName}.php with methods {methodOne}, {methodTwo}, etc., create separate test files:

tests/Feature/Controllers/{Path}/{ControllerName}/
@ronssij
ronssij / stripe-cashier-testing.md
Created February 19, 2026 09:57
Laravel Boost Cashier tests guidelines

Stripe / Cashier Testing

When testing an application that uses Cashier, you may mock the actual HTTP requests to the Stripe API; however, this requires you to partially re-implement Cashier's own behavior. Therefore, we recommend allowing your tests to hit the actual Stripe API. While this is slower, it provides more confidence that your application is working as expected and any slow tests may be placed within their own Pest / PHPUnit testing group.

Real Stripe API Testing

Prefer creating real Stripe test accounts and making actual API calls over mocking. This approach:

  • Tests integration: Verifies your code works with the actual Stripe API
  • Catches API changes: Stripe API changes will be caught by tests
@ronssij
ronssij / roman_numerals.php
Last active April 16, 2024 12:21
Laravel collection roman numeral conversion
<?php
$roman = ['i' => 1, 'v' => 5, 'x' => 10, 'l' => 50, 'c' => 100, 'd' => 500, 'm' => 1000];
$value = 'IX';
$result = 0;
$prevValue = 0;
if (preg_match('/[^ivxlcdm]|i{4,}|x{4,}|c{4,}|m{4,}|v{2,}|l{2,}|d{2,}/i', $value)) {
return "invalid format";
@ronssij
ronssij / SequentialIncrementNullColumns.php
Last active February 9, 2024 18:00
Laravel: Sequentially Incrementing Null Columns in a Database
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class SequentialIncrementNullColumns extends Seeder
{
public function run(): void
@ronssij
ronssij / useForm.ts
Created November 30, 2023 05:51
Vue3 Form Composables
const form = <TFormData>(formData: TFormData) => {
const $originalData = useCloneDeep(formData) as object;
const $errors = ref({});
const $busy = ref(false);
let _data = formData as object;
const $setErrors = <TErrors>(errors: object | TErrors) => {
return ($errors.value = errors || {});
};
@ronssij
ronssij / JustifyParagraph.php
Last active February 5, 2024 17:35
Jsutify string in PHP(Laravel)
<?php
$string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis adipiscing sodales ipsum sem ac. Orci sem nisl rutrum sagittis sed id. In tellus mauris tempor in at. Lorem ac sit tortor, eu sit elementum vestibulum ultrices egestas. In nunc, aliquet nulla quis. Tristique molestie integer ac ullamcorper dolor. Donec id erat turpis lobortis et egestas phasellus. Sit elit suspendisse porttitor egestas. Augue id mollis enim, eget sapien, luctus. Tortor, malesuada morbi et dui pretium adipiscing dui id rhoncus. Vitae et eget luctus ut nec donec. Vulputate pharetra tempus, congue eu commodo praesent imperdiet sapien. Vitae eleifend lobortis tellus enim, aliquam fermentum at venenatis. Mattis fringilla id viverra in metus pharetra, rutrum eget porta.";
$limit = 30;
$lines = [];
$collected = collect([]);
$words = explode(" ", $string);
@ronssij
ronssij / natural_sort_function.php
Created October 4, 2023 17:06
Natural sorting for laravel mysql
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
class AddNaturalSortFunction extends Migration
{
/**
@ronssij
ronssij / icon.vue
Created May 20, 2022 20:54
Functional vue icon component
<script>
import { has, map } from 'lodash'
export default {
name: 'AftIcon',
functional: true,
props: {
tag: {
@ronssij
ronssij / icon-colors.js
Last active May 20, 2022 20:52
Extending Tailwind CSS color palattes to create custom prefxied colors.
const plugin = require('tailwindcss/plugin')
/**
* Utlizes tailwind colors config and icon-{color} class is created, analog to bg- and text- classes.
*
* eg. class="icon-white"
*/
const generateColors = (e, colors, prefix) =>
Object.keys(colors).reduce((acc, key) => {
if (typeof colors[key] === 'string') {