public function testSettingGenerator()
 {
     $database = m::mock('Arrilot\\DataAnonymization\\Database\\DatabaseInterface');
     $anonymizer = new Anonymizer($database);
     $this->assertNull($anonymizer->getGenerator());
     $anonymizer->setGenerator(new StdClass());
     $this->assertInstanceOf('StdClass', $anonymizer->getGenerator());
 }
 public function testRun()
 {
     $database = m::mock('Arrilot\\DataAnonymization\\Database\\DatabaseInterface');
     $database->shouldReceive('getRows')->twice()->andReturn([['id' => 1, 'name' => 'Jane', 'email' => '*****@*****.**'], ['id' => 2, 'name' => 'Jack', 'email' => '*****@*****.**']]);
     $database->shouldReceive('updateByPrimary')->times(4);
     $anonymizer = new Anonymizer($database);
     $anonymizer->table('users', function (Blueprint $table) {
         $table->primary('id');
         $table->column('email')->replaceWith('*****@*****.**');
         $table->column('name')->replaceWith('john');
     });
     $anonymizer->run();
 }
Esempio n. 3
0
#!/usr/bin/env php
<?php 
use Arrilot\DataAnonymization\Anonymizer;
use Arrilot\DataAnonymization\Blueprint;
use Arrilot\DataAnonymization\Database\SqlDatabase;
use Faker\Generator as Faker;
require './vendor/autoload.php';
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = '******';
$password = '******';
$database = new SqlDatabase($dsn, $user, $password);
$anonymizer = new Anonymizer($database);
// Describe `users` table.
$anonymizer->table('users', function (Blueprint $table) {
    // Specify a primary key of the table. For composite key an array should be passed in.
    // This step can be skipped if you have `id` as a primary key.
    $table->primary('id');
    // Replace with static data.
    $table->column('email')->replaceWith('*****@*****.**');
    // Replace with dynamic data.
    $table->column('email2')->replaceWith(function (Faker $faker) {
        return $faker->email;
    });
    // Use some constraints.
    $table->column('email3')->where('ID != 1')->replaceWith(function (Faker $faker) {
        return $faker->unique()->email;
    });
});
$anonymizer->run();
echo 'Anonymization has been completed!';
 /**
  * Describe a table with a given callback.
  *
  * @param string   $name
  * @param callable $callback
  *
  * @return void
  */
 public function table($name, callable $callback)
 {
     $this->core->table($name, $callback);
 }
Esempio n. 5
0
#!/usr/bin/env php
<?php 
use Arrilot\DataAnonymization\Anonymizer;
use Arrilot\DataAnonymization\Blueprint;
use Arrilot\DataAnonymization\Database\SqlDatabase;
require './vendor/autoload.php';
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = '******';
$password = '******';
$database = new SqlDatabase($dsn, $user, $password);
$anonymizer = new Anonymizer($database);
// Describe `users` table.
$anonymizer->table('users', function (Blueprint $table) {
    // Specify a primary key of the table. An array should be passed in for composite key.
    // This step can be skipped if you have `id` as a primary key.
    // You can change default primary key for all tables with `Blueprint::setDefaultPrimary('ID')`
    $table->primary('id');
    // Replace with static data.
    $table->column('email1')->replaceWith('*****@*****.**');
    // Use #row# template to get "*****@*****.**", "*****@*****.**", "*****@*****.**"
    $table->column('email2')->replaceWith('email_#row#@example.com');
    // To replace with dynamic data a $generator is needed.
    // Any generator object can be set like that - `$anonymizer->setGenerator($generator);`
    // A simpler way is just to do `require fzaninotto/Faker` and it will be set automatically.
    $table->column('email3')->replaceWith(function ($generator) {
        return $generator->email;
    });
    // Use `where` to leave some data untouched.
    // If you don't list a column here, it will be left untouched too.
    $table->column('email4')->where('ID != 1')->replaceWith(function ($generator) {
        return $generator->unique()->email;