Skip to content

Commit

Permalink
Fix: Travis tests (#172)
Browse files Browse the repository at this point in the history
* PHP Parse error:  syntax error, unexpected ''

* UPDATE: Composer dependencies & path/settings

* FIX: phpcs LINT

* FIX: PHPStan tests

* FIX: phpunit tests

Co-authored-by: Marco Hermo <[email protected]>
  • Loading branch information
mattclegg and ssmarco committed Jun 1, 2020
1 parent ff3d999 commit 32ab654
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
app
resources
vendor
.DS_Store
.htaccess
behat.yml
composer.lock
index.php
web.config
39 changes: 21 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
language: php

services:
- mysql

env:
global:
- COMPOSER_ROOT_VERSION=5.0.x-dev
- PHPSTAN_VERSION=0.9.2
- PHPSTAN_VERSION=^0.12
- SS_BASE_URL="http://localhost/"

matrix:
include:
# NOTE(Jake): 2018-05-02
#
# PHP 5.6 is not supported due to undebuggable errors in Travis
# occuring in the config layer.
#
#- php: 5.6
# env: DB=MYSQL RECIPE_VERSION=1.0.x-dev
- php: 7.0
env: DB=MYSQL RECIPE_VERSION=1.1.x-dev PHPCS_TEST=1
- php: 7.1
env: DB=MYSQL RECIPE_VERSION=1.2.x-dev
- php: 7.2
env: DB=MYSQL RECIPE_VERSION=1.2.x-dev # NOTE(Jake): 2018-05-03, Needs fixes PHP include fixes, - PHPSTAN_TEST=1
env: DB=MYSQL RECIPE_VERSION=4.5.x-dev PHPCS_TEST=1
- php: 7.3
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPSTAN_TEST=1
- php: 7.4
env: DB=MYSQL RECIPE_VERSION=4.x-dev PHPUNIT_TEST=1

before_script:
# Extra $PATH
- export PATH=./vendor/bin:$PATH

# Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini
- echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

# Install composer dependencies
- composer validate
- composer require --no-update silverstripe/recipe-cms:$RECIPE_VERSION
- if [[ $PHPSTAN_TEST ]]; then composer require --no-update phpstan/phpstan-shim:$PHPSTAN_VERSION; fi
- composer require --no-update silverstripe/recipe-testing:^1 silverstripe/recipe-cms:$RECIPE_VERSION
- if [[ $PHPSTAN_TEST ]]; then composer require --no-update phpstan/phpstan:$PHPSTAN_VERSION; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

script:
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --ignore=tests/bootstrap-phpstan.php src/ tests/ *.php; fi
- if [[ $PHPSTAN_TEST ]]; then vendor/bin/phpstan analyse src/ tests/ -c "phpstan.neon" -a "tests/bootstrap-phpstan.php" --level 3; fi
- vendor/bin/phpunit
- if [[ $PHPCS_TEST ]]; then phpcs --ignore=tests/bootstrap-phpstan.php src/ tests/ *.php; fi
- if [[ $PHPSTAN_TEST ]]; then phpstan analyse src/ tests/ -c "phpstan.neon" -a "tests/bootstrap-phpstan.php" --level 3; fi
- if [[ $PHPUNIT_TEST ]]; then phpunit; fi
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ parameters:
- redirect
excludes_analyse:
- silverstripe-cache
exclude_files:
- tests/bootstrap-phpstan.php
ignoreErrors:
# No SilverStripe 4 support yet
- '%undefined property SilverStripe\\Security\\Member::%'
- '%undefined property SilverStripe\\ORM\\DataObject::%'
- '%undefined property SilverStripe\\SiteConfig\\SiteConfig::%'
# Ignore because added by MemberProfileExtension
- '%undefined method SilverStripe\\Security\\Member::getPublicFields()%'
- '%undefined method SilverStripe\\Security\\Member::setPublicFields()%'
Expand All @@ -23,5 +21,3 @@ parameters:
# Unsupported introspection level
- '%Call to an undefined method SilverStripe\\Forms\\FormField::setCanBeEmpty()%'
- '%Call to an undefined method SilverStripe\\Forms\\Form::enableSpamProtection()%'
# Ignore modules / classes that may or may not be installed
- '%UndefinedOffset\\SortableGridField\\Forms\\GridFieldSortableRows not found%'
17 changes: 14 additions & 3 deletions src/Forms/CheckableVisibilityField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Symbiote\MemberProfiles\Forms;

use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\Forms\ReadonlyField;
Expand All @@ -10,6 +11,8 @@
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CheckboxField_Readonly;
use SilverStripe\ORM\FieldType\DBHTMLText;
use Symbiote\MemberProfiles\Extensions\MemberProfileExtension;

/**
* A wrapper around a field to add a checkbox to optionally mark it as visible.
Expand All @@ -25,7 +28,7 @@ class CheckableVisibilityField extends FormField
private $child;

/**
* @var CheckboxField|CheckboxField_Readonly
* @var FormField|CheckboxField|CheckboxField_Readonly
*/
private $checkbox;

Expand Down Expand Up @@ -54,7 +57,7 @@ public function getChild()
}

/**
* @return CheckboxField|CheckboxField_Readonly
* @return FormField|CheckboxField|CheckboxField_Readonly
*/
public function getCheckbox()
{
Expand All @@ -72,6 +75,11 @@ public function makeAlwaysVisible()
return $this;
}

/**
* @param mixed $value Either the parent object, or array of source data being loaded
* @param array|MemberProfileExtension $data {@see Form::loadDataFrom}
* @return $this
*/
public function setValue($value, $data = array())
{
$this->child->setValue($value);
Expand Down Expand Up @@ -143,7 +151,10 @@ public function setForm($form)

public function Field($properties = array())
{
return $this->child->Field() . ' ' . $this->checkbox->Field();
return DBHTMLText::create_field(
'HTMLFragment',
$this->child->Field() . ' ' . $this->checkbox->Field()
);
}

public function Title()
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/MemberProfileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function php($data)

//pass in the Unique Identifier Field (usually Email)
$idField = Member::config()->get('unique_identifier_field');
if(isset($data[$idField])) {
if (isset($data[$idField])) {
$member->$idField = $data[$idField];
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Pages/MemberApprovalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PageController;

use SilverStripe\Core\Config\Config;
use SilverStripe\Security\Member;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Security;
Expand Down Expand Up @@ -73,7 +74,7 @@ public function index($request)
));
}

if ($this->config()->redirect_to_admin) {
if (Config::inst()->get(self::class, 'redirect_to_admin')) {
$controller = singleton(SecurityAdmin::class);
if (!$controller->canView()) {
return Security::permissionFailure();
Expand Down
21 changes: 13 additions & 8 deletions src/Pages/MemberProfilePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* @method \SilverStripe\ORM\DataList|\SilverStripe\Security\Group[] Groups()
* @method \SilverStripe\ORM\DataList|\SilverStripe\Security\Group[] SelectableGroups()
* @method \SilverStripe\ORM\DataList|\SilverStripe\Security\Group[] ApprovalGroups()
* @method \SilverStripe\ORM\HasManyList|MemberProfileFieldsSection[] Sections()
*/
class MemberProfilePage extends Page
{
Expand Down Expand Up @@ -238,14 +239,18 @@ public function getCMSFields()
)
));

$grid->getComponentByType(GridFieldDataColumns::class)->setFieldFormatting(array(
'Unique' => function ($val, $obj) {
return $obj->dbObject('Unique')->Nice();
},
'Required' => function ($val, $obj) {
return $obj->dbObject('Required')->Nice();
}
));
/* @var GridFieldDataColumns $dataColumns */
$dataColumns = $grid->getComponentByType(GridFieldDataColumns::class);
if (method_exists($dataColumns, 'setFieldFormatting')) {
$dataColumns->setFieldFormatting(array(
'Unique' => function ($val, $obj) {
return $obj->dbObject('Unique')->Nice();
},
'Required' => function ($val, $obj) {
return $obj->dbObject('Required')->Nice();
}
));
}

if (class_exists(GridFieldOrderableRows::class)) {
$grid->addComponent(GridFieldOrderableRows::create('Sort'));
Expand Down
14 changes: 8 additions & 6 deletions src/Pages/MemberProfilePageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\Control\Session;
use SilverStripe\Security\IdentityStore;
use SilverStripe\Security\Member;
use SilverStripe\Security\Member_GroupSet;
use SilverStripe\Security\Security;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\Controller;
Expand Down Expand Up @@ -73,7 +74,7 @@ class MemberProfilePageController extends PageController
];

/**
* @return array|ViewableData_Customised
* @return HTTPResponse
*/
public function index(HTTPRequest $request)
{
Expand All @@ -89,7 +90,7 @@ public function index(HTTPRequest $request)
/**
* Allow users to register if registration is enabled.
*
* @return array|ViewableData_Customised
* @return HTTPResponse|ViewableData_Customised
*/
protected function indexRegister()
{
Expand Down Expand Up @@ -117,7 +118,7 @@ protected function indexRegister()
* If editing is disabled, but the current user can add users, then they
* are redirected to the add user page.
*
* @return array|ViewableData_Customised
* @return HTTPResponse|ViewableData_Customised
*/
protected function indexProfile()
{
Expand Down Expand Up @@ -192,8 +193,8 @@ public function RegisterForm()
new MemberProfileValidator($this->Fields())
);


if ($form->hasExtension(FormSpamProtectionExtension::class)) {
if (class_exists(FormSpamProtectionExtension::class)
&& $form->hasExtension(FormSpamProtectionExtension::class)) {
$form->enableSpamProtection();
}
$this->extend('updateRegisterForm', $form);
Expand Down Expand Up @@ -271,7 +272,7 @@ public function ProfileForm()
*/
public function save(array $data, Form $form)
{
$member = Member::currentUser();
$member = Security::getCurrentUser();

$groupIds = $this->getSettableGroupIdsFrom($form, $member);
$member->Groups()->setByIDList($groupIds);
Expand All @@ -298,6 +299,7 @@ public function save(array $data, Form $form)
_t('MemberProfiles.PROFILEUPDATED', 'Your profile has been updated.'),
'good'
);

return $this->redirectBack();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/MemberConfirmationAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testManualConfirmation()
$this->assertEquals(true, (bool) $member->NeedsValidation);

$this->getSecurityAdmin();
$this->submitForm('Form_ItemEditForm', null, array (
$this->submitForm('Form_ItemEditForm', 'action_doSave', array (
'ManualEmailValidation' => 'confirm'
));

Expand All @@ -40,7 +40,7 @@ public function testResendConfirmationEmail()
$this->assertEquals(true, (bool) $member->NeedsValidation);

$this->getSecurityAdmin();
$this->submitForm('Form_ItemEditForm', null, array (
$this->submitForm('Form_ItemEditForm', 'action_doSave', array (
'ManualEmailValidation' => 'resend'
));

Expand Down
5 changes: 3 additions & 2 deletions tests/bootstrap-phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
$BOOTSTRAP_FILE = $PROJECT_DIR . '/vendor/silverstripe/cms/tests/bootstrap.php';
if (!file_exists($BOOTSTRAP_FILE)) {
// Handle Travis build
$PROJECT_DIR = dirname(__FILE__).'/../..';
$BOOTSTRAP_FILE = $PROJECT_DIR.'/silverstripe/cms/src/includes/autoload.php';
$PROJECT_DIR = dirname(__FILE__).'/..';
$BOOTSTRAP_FILE = $PROJECT_DIR.'/vendor/silverstripe/cms/tests/bootstrap.php';
}

require_once($BOOTSTRAP_FILE);

// NOTE(Jake): 2018-05-01
Expand Down

0 comments on commit 32ab654

Please sign in to comment.