<?php

use BB\Entities\Payment;
use BB\Entities\User;
$I = new UnitTester($scenario);
$I->wantTo('confirm the payment helper fetches the correct payment date');
//Create a user record
$user = User::create(['given_name' => 'Test', 'family_name' => 'Person', 'email' => '*****@*****.**']);
$date = \BB\Helpers\MembershipPayments::lastUserPaymentDate($user->id);
$I->assertFalse($date, 'Date should be false as no payments exist');
//Create some payment records
\BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-01-01', 'payment_date' => '2014-01-01', 'status' => 'paid']);
Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'paid', 'created_at' => '2014-01-01']);
\BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-06-01', 'status' => 'processing']);
Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'pending', 'created_at' => '2014-06-01']);
\BB\Entities\SubscriptionCharge::create(['user_id' => $user->id, 'charge_date' => '2014-08-01', 'status' => 'cancelled']);
Payment::create(['reason' => 'subscription', 'source' => 'other', 'user_id' => $user->id, 'amount' => 20, 'amount_minus_fee' => 20, 'status' => 'cancelled', 'created_at' => '2014-08-01']);
//Now we have some payments re-fetch the last payment date
$date = \BB\Helpers\MembershipPayments::lastUserPaymentDate($user->id);
//Make sure its a date that's returned
$I->assertEquals(get_parent_class($date), 'DateTime');
//Confirm the datetime matched the first payment record, the only paid one
$I->assertEquals(new \Carbon\Carbon('2014-01-01'), $date);
}
Capsule::table('locations')->truncate();
Location::create(['name' => 'Cardiff', 'lat' => 51.4833, 'lng' => 3.1833]);
Location::create(['name' => 'Newport', 'lat' => 51.5833, 'lng' => 3.0]);
Location::create(['name' => 'Swansea', 'lat' => 51.6167, 'lng' => 3.95]);
Location::create(['name' => 'London', 'lat' => 51.5072, 'lng' => 0.1275]);
/*for ($i = 0; $i < 1000; $i++)
{
    Location::create(['location' => $i, 'lat' => $i, 'lng' => $i, 'updated_at' => $i, 'created_at' => $i]);
}*/
$I = new UnitTester($scenario);
$lat = 51.4833;
$lng = 3.1833;
$location = new Location();
$locations = $location->lat($lat)->lng($lng)->within(20, 'miles')->get();
$I->wantTo('find locations within 5 miles');
$locations = Location::within(5, 'miles', $lat, $lng)->get();
$I->assertEquals(1, $locations->count(), 'One location found within 5 miles');
$I->wantTo('find 2 locations within 132000 feet (25 miles)');
$locations = Location::within(132000, 'feet', $lat, $lng)->get();
$I->assertEquals(2, $locations->count(), 'One location found within 132000 feet');
$I->wantTo('find locations within 55 miles');
$locations = Location::within(55, 'miles', $lat, $lng)->get();
$I->assertEquals(3, $locations->count(), 'Three locations found within 55 miles');
$I->wantTo('find locations within 5 kilometers');
$locations = Location::within(5, 'kilometers', $lat, $lng)->get();
$I->assertEquals(1, $locations->count(), 'One location found within 5 kilometers');
$I->wantTo('find locations within 5 nautical miles');
$locations = Location::within(5, 'nautical_miles', $lat, $lng)->get();
$I->assertEquals(1, $locations->count(), 'One location found within 5 nautical miles');
$I->wantTo('find locations within 5000 meters');
<?php

$I = new UnitTester($scenario);
$I->wantTo('mark as done deposit ticket');
$app = \Slim\Slim::getInstance();
$app->container->singleton("DepositMarkAsDoneService", function () use($app) {
    $deposit_repository = \Codeception\Util\Stub::make("\\Mabes\\Entity\\DepositRepository", ["findOneBy" => function () {
        $deposit = new \Mabes\Entity\Deposit();
        $deposit->setStatus(\Mabes\Entity\Deposit::STATUS_OPEN);
        return $deposit;
    }, "save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\DepositMarkAsDoneService($deposit_repository, $validator, $event_emitter);
});
$data = ["deposit_id" => 1];
$command = new \Mabes\Service\Command\DepositMarkAsDoneCommand();
$command->massAssignment($data);
$service = $app->container->get("DepositMarkAsDoneService");
$I->assertEquals(true, $service->execute($command));
// EOF
<?php

$I = new UnitTester($scenario);
$I->wantTo('perform actions and see result');
Beispiel #5
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('add member');
$app = \Slim\Slim::getInstance();
$app->container->singleton("CreateNewMemberService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["save" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    return new Mabes\Service\CreateMemberService($member_repo, $validator, $event_emitter);
});
// test
$data = ["account_id" => "123", "email" => "*****@*****.**", "phone" => "123456789", "fullname" => "John Doe", "bank_name" => "BCA", "account_number" => "123456789", "account_holder" => "John Doe", "address" => "55335 Corwin Rd # A970289, Elkhart, Indiana 46514, USA"];
$command = new \Mabes\Service\Command\CreateMemberCommand();
$command->massAssignment($data);
$create_member_service = $app->container->get("CreateNewMemberService");
$I->assertTrue($create_member_service->execute($command));
Beispiel #6
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('add withdrawal');
$app = \Slim\Slim::getInstance();
$app->container->singleton("CreateWithdrawalService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["findOneBy" => function () {
        $member = new \Mabes\Entity\Member();
        $member->setAccountId(12345);
        return $member;
    }]);
    $wd_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\WithdrawalRepository", ["save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\CreateWithdrawalService($member_repo, $wd_repo, $validator, $event_emitter);
});
$data = ["account_id" => 1234, "amount" => 1];
$command = new \Mabes\Service\Command\CreateWithdrawalCommand();
$command->massAssignment($data);
$service = $app->container->get("CreateWithdrawalService");
$I->assertEquals(0, $service->execute($command));
// EOF
<?php

$I = new UnitTester($scenario);
$I->wantTo('confirm the stats helper works as expected');
$I->assertEquals(0, \BB\Helpers\StatsHelper::roundToNearest(2), '2 should round to 0');
$I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(4), '4 should round to 5');
$I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(5), '5 should stay as 5');
$I->assertEquals(5, \BB\Helpers\StatsHelper::roundToNearest(6), '6 should round down to 5');
$I->assertEquals(10, \BB\Helpers\StatsHelper::roundToNearest(7.5), '7.5 should round up to 10');
$I->assertEquals(10, \BB\Helpers\StatsHelper::roundToNearest(10), '10 should stay as 10');
<?php

use Carbon\Carbon;
$I = new UnitTester($scenario);
$I->wantTo('confirm the grace period dates are correct');
$paypalDate = \BB\Helpers\MembershipPayments::getSubGracePeriodDate('paypal');
//Make sure its a date that's returned
$I->assertEquals(get_parent_class($paypalDate), 'DateTime');
//Confirm the date is what we expect
$I->assertEquals(Carbon::now()->subDays(7)->setTime(0, 0, 0), $paypalDate);
<?php

$I = new UnitTester($scenario);
$I->wantTo('mark as done withdrawal ticket');
$app = \Slim\Slim::getInstance();
$app->container->singleton("WithdrawalMarkAsDoneService", function () use($app) {
    $withdrawal_repository = \Codeception\Util\Stub::make("\\Mabes\\Entity\\WithdrawalRepository", ["findOneBy" => function () {
        $withdrawal = new \Mabes\Entity\Withdrawal();
        $withdrawal->setStatus(\Mabes\Entity\Withdrawal::STATUS_OPEN);
        return $withdrawal;
    }, "save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\WithdrawalMarkAsDoneService($withdrawal_repository, $validator, $event_emitter);
});
$data = ["withdrawal_id" => 1];
$command = new \Mabes\Service\Command\WithdrawalMarkAsDoneCommand();
$command->massAssignment($data);
$service = $app->container->get("WithdrawalMarkAsDoneService");
$I->assertEquals(true, $service->execute($command));
// EOF
<?php

$I = new UnitTester($scenario);
$I->wantTo('Test to verify if the tester is working');
<?php

$I = new UnitTester($scenario);
$I->wantTo('add investor password');
$app = \Slim\Slim::getInstance();
$app->container->singleton("AddInvestorPasswordService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["findOneBy" => function () {
        $member = new \Mabes\Entity\Member();
        $member->setAccountId(12345);
        $member->setCreatedAt(new \DateTime());
        return $member;
    }]);
    $investor_pass_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\InvestorPasswordRepository", ["save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\AddInvestorPasswordService($member_repo, $investor_pass_repo, $validator, $event_emitter);
});
$data = ["account_id" => 1234, "mt4_account" => 4321, "investor_password" => "AbcgTdy"];
$command = new \Mabes\Service\Command\AddInvestorPasswordCommand();
$command->massAssignment($data);
$service = $app->container->get("AddInvestorPasswordService");
$I->assertEquals(true, $service->execute($command));
// EOF
<?php

$I = new UnitTester($scenario);
$I->wantTo('create islamic account');
$app = \Slim\Slim::getInstance();
$app->container->singleton("CreateIslamicAccountService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["findOneBy" => function () {
        $member = new \Mabes\Entity\Member();
        $member->setAccountId(12345);
        $member->setCreatedAt(new \DateTime());
        return $member;
    }]);
    $rebate_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\ClaimRebateRepository", ["save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\CreateIslamicAccountService($member_repo, $validator, $event_emitter);
});
$data = ["account_id" => 1234, "mt4_account" => 12345];
$command = new \Mabes\Service\Command\CreateIslamicAccountCommand();
$command->massAssignment($data);
$service = $app->container->get("CreateIslamicAccountService");
$I->assertEquals(true, $service->execute($command));
Beispiel #13
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('auth staff');
$app = \Slim\Slim::getInstance();
$app->container->singleton("AuthService", function () use($app) {
    $hash_service = new \Mabes\Service\HashService("1234");
    $hash = $hash_service->hash();
    $staff_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\StaffRepository", ["findOneBy" => function () use($hash) {
        $staff = new \Mabes\Entity\Staff();
        $staff->setPassword($hash);
        return $staff;
    }, "save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $auth_password = \Codeception\Util\Stub::make("Mabes\\Service\\AuthPasswordService");
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\AuthService($staff_repo, $auth_password, $validator, $event_emitter);
});
$data = ["username" => "john", "password" => "1234"];
$command = new \Mabes\Service\Command\AuthCommand();
$command->massAssignment($data);
$service = $app->container->get("AuthService");
$I->assertTrue($service->execute($command));
// EOF
Beispiel #14
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('add staff');
$app = \Slim\Slim::getInstance();
$app->container->singleton("CreateStaffService", function () use($app) {
    $staff_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\StaffRepository", ["findOneBy" => function () {
        return false;
    }, "save" => function () {
        return true;
    }]);
    $hash_service = \Codeception\Util\Stub::make("Mabes\\Service\\HashService");
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\CreateStaffService($staff_repo, $hash_service, $validator, $event_emitter);
});
$data = ["username" => "john", "password" => "123"];
$command = new \Mabes\Service\Command\CreateStaffCommand();
$command->massAssignment($data);
$service = $app->container->get("CreateStaffService");
$I->assertTrue($service->execute($command));
// EOF
Beispiel #15
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('claim rebate');
$app = \Slim\Slim::getInstance();
$app->container->singleton("ClaimRebateService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["findOneBy" => function () {
        $member = new \Mabes\Entity\Member();
        $member->setAccountId(12345);
        $member->setCreatedAt(new \DateTime());
        return $member;
    }]);
    $rebate_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\ClaimRebateRepository", ["save" => function () {
        return true;
    }]);
    $event_emitter = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\ClaimRebateService($member_repo, $rebate_repo, $validator, $event_emitter);
});
$data = ["account_id" => 1234, "mt4_account" => 4321, "type" => "BANK"];
$command = new \Mabes\Service\Command\ClaimRebateCommand();
$command->massAssignment($data);
$service = $app->container->get("ClaimRebateService");
$I->assertEquals(true, $service->execute($command));
// EOF
Beispiel #16
0
<?php

$I = new UnitTester($scenario);
$I->wantTo('add deposit');
$app = \Slim\Slim::getInstance();
$app->container->singleton("CreateDepositService", function () use($app) {
    $member_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\MemberRepository", ["findOneBy" => function () {
        $member = new \Mabes\Entity\Member();
        $member->setAccountId(12345);
        $member->setCreatedAt(new \DateTime());
        return $member;
    }]);
    $depo_repo = \Codeception\Util\Stub::make("\\Mabes\\Entity\\DepositRepository", ["save" => function () {
        return true;
    }]);
    $event_emittier = \Codeception\Util\Stub::make("\\Evenement\\EventEmitter", ["emit" => function () {
        return true;
    }]);
    $validator = $app->container->get("Validator");
    return new \Mabes\Service\CreateDepositService($member_repo, $depo_repo, $validator, $event_emittier);
});
$data = ["account_id" => 1234, "amount_idr" => 12000, "amount_usd" => 1.2, "to_bank" => "BCA"];
$command = new \Mabes\Service\Command\CreateDepositCommand();
$command->massAssignment($data);
$service = $app->container->get("CreateDepositService");
$I->assertEquals(0, $service->execute($command));
// EOF