Skip to content

Instantly share code, notes, and snippets.

@angelxmoreno
Created September 22, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelxmoreno/b8862885dc4098e3a9a63ab256ce0ccc to your computer and use it in GitHub Desktop.
Save angelxmoreno/b8862885dc4098e3a9a63ab256ce0ccc to your computer and use it in GitHub Desktop.
Kahlan test
<?php
class Helper {
public function render(array $payment_methods, $error_saving_plans = false, $boleto_tab_checked = false)
{
$html = '';
foreach (self::TAB_NAMES as $tab_name) {
$payment_enabled = $this->isPaymentEnabled($tab_name, $payment_methods);
$tab_disabled = $this->isTabDisabled($tab_name, $error_saving_plans);
$checked = $this->shouldBeChecked($tab_name, $payment_enabled, $tab_disabled, $boleto_tab_checked);
if ($payment_enabled) {
$html .= $this->getPartial(self::PARTIALS_PATH . $tab_name, [
'disabled_status' => $tab_disabled ? 'disabled' : '',
'checked_status' => $checked ? 'checked' : '',
]);
}
}
return $html;
}
}
// The test
it('pulls the partial for enabled tabs', function () {
$payment_methods = [
TabControllerViewHelper::BOLETO,
TabControllerViewHelper::PAYSAFE
];
foreach (TabControllerViewHelper::TAB_NAMES as $tab_name) {
expect(TabControllerViewHelper::class)
->toReceive('getPartial')
->with(TabControllerViewHelper::PARTIALS_PATH . $tab_name);
}
expect(TabControllerViewHelper::class)
->not
->toReceive('getPartial')
->with(TabControllerViewHelper::PARTIALS_PATH . TabControllerViewHelper::PAYSAFE);
$this->helper->render($payment_methods);
});
//the result
render
✘ it pulls the partial for enabled tabs
expect->toReceive() failed in `/vendor/kahlan/kahlan/src/Matcher/ToReceive.php` line 89
actual received:
(array) [
0 => "setDI",
1 => "render",
2 => "isPaymentEnabled",
3 => "isTabDisabled",
4 => "shouldBeChecked",
5 => "getDefaultTab",
6 => "isPaymentEnabled",
7 => "isTabDisabled",
8 => "shouldBeChecked",
9 => "getDefaultTab",
10 => "isPaymentEnabled",
11 => "isTabDisabled",
12 => "shouldBeChecked",
13 => "getDefaultTab"
]
expected:
(string) "getPartial"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment