PHP code example of jainec / hyperf-fakie

1. Go to this page and download the library: Download jainec/hyperf-fakie library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jainec / hyperf-fakie example snippets




declare(strict_types=1);

return [
    'rules' => [
        'App\Entity\User' => [
            'type' => array_rand(['CONSUMER', 'SELLER']),
        ],
        'App\Entity\Order' => [
            'type' => array_rand(['VIRTUAL', 'PHYSICAL']),
        ],
        'Class' => [
            'property1' => 'rule1',
            'property2' => 'rule2',
        ],
    ],
];


// Ex.: Generating an OrderHistory object for testing purposes
$order = new Order(
    id: rand(),
    type: array_rand(['VIRTUAL', 'PHYSICAL']),
    amount: rand(),
    value: rand() / 100,
);

$user = new User(
    name: Str::random(),
    telephone: Str::random(),
    city: Str::random(),
);

$order_history = new OrderHistory(
    id: rand(),
    description: Str::random(),
    order: $order,
    user: $user,
);

// Ex.: Generating an OrderHistory object for testing purposes with fakie
$order_history = Fakie::object(OrderHistory::class)->create();

$user = Fakie::object(OrderHistory::class)->create([
    'description' => 'Specific description for specific test case'
]);

$user = Fakie::object(UserDTO::class, 'fromArray')->create();

$user = Fakie::object(UserDTO::class, 'fromArray')->excludeProperties(['type', 'age'])->create();



declare(strict_types=1);

return [
    'rules' => [
        'App\Entity\OrderHistory' => [
            'order' => Fakie::object(Order::class), // Don't call the create() method here
            'user' => Fakie::object(User::class, 'fromArray'), // Don't call the create() method here
        ],
    ],
];
shell
php bin/hyperf.php vendor:publish jainec/hyperf-fakie
shell
config/autoload/fakie.php