Browse Source

Fix PHP74 warnings.

mscherer 6 years ago
parent
commit
e674591838

+ 1 - 6
src/Model/Behavior/PasswordableBehavior.php

@@ -124,6 +124,7 @@ class PasswordableBehavior extends Behavior {
 	 *
 	 *
 	 * @param array $config The configuration array this behavior is using.
 	 * @param array $config The configuration array this behavior is using.
 	 * @return void
 	 * @return void
+	 * @throws \RuntimeException
 	 */
 	 */
 	public function initialize(array $config) {
 	public function initialize(array $config) {
 		$formField = $this->_config['formField'];
 		$formField = $this->_config['formField'];
@@ -284,17 +285,11 @@ class PasswordableBehavior extends Behavior {
 			$current = $entity->get($formFieldCurrent);
 			$current = $entity->get($formFieldCurrent);
 			$new = $entity->get($formField) || $entity->get($formFieldRepeat);
 			$new = $entity->get($formField) || $entity->get($formFieldRepeat);
 			if (!$new && !$current) {
 			if (!$new && !$current) {
-				//$validator->remove($formField); // tmp only!
-				//unset($Model->validate[$formField]);
 				$entity->unsetProperty($formField);
 				$entity->unsetProperty($formField);
 				if ($this->_config['confirm']) {
 				if ($this->_config['confirm']) {
-					//$validator->remove($formFieldRepeat); // tmp only!
-					//unset($Model->validate[$formFieldRepeat]);
 					$entity->unsetProperty($formFieldRepeat);
 					$entity->unsetProperty($formFieldRepeat);
 				}
 				}
 				if ($this->_config['current']) {
 				if ($this->_config['current']) {
-					//$validator->remove($formFieldCurrent); // tmp only!
-					//unset($Model->validate[$formFieldCurrent]);
 					$entity->unsetProperty($formFieldCurrent);
 					$entity->unsetProperty($formFieldCurrent);
 				}
 				}
 				return;
 				return;

+ 3 - 3
src/Model/Behavior/SluggedBehavior.php

@@ -213,14 +213,14 @@ class SluggedBehavior extends Behavior {
 			$overwrite = true;
 			$overwrite = true;
 		}
 		}
 		if ($overwrite || $entity->isNew() || !$entity->get($this->_config['field'])) {
 		if ($overwrite || $entity->isNew() || !$entity->get($this->_config['field'])) {
-			$slug = [];
+			$pieces = [];
 			foreach ((array)$this->_config['label'] as $v) {
 			foreach ((array)$this->_config['label'] as $v) {
 				$v = $entity->get($v);
 				$v = $entity->get($v);
 				if ($v !== null && $v !== '') {
 				if ($v !== null && $v !== '') {
-					$slug[] = $v;
+					$pieces[] = $v;
 				}
 				}
 			}
 			}
-			$slug = implode($slug, $this->_config['separator']);
+			$slug = implode($this->_config['separator'], $pieces);
 			$slug = $this->generateSlug($slug, $entity);
 			$slug = $this->generateSlug($slug, $entity);
 			$entity->set($this->_config['field'], $slug);
 			$entity->set($this->_config['field'], $slug);
 		}
 		}

+ 9 - 9
tests/TestCase/Model/Behavior/PasswordableBehaviorTest.php

@@ -393,7 +393,7 @@ class PasswordableBehaviorTest extends TestCase {
 			'pwd' => '123456',
 			'pwd' => '123456',
 			'pwd_repeat' => '123456'
 			'pwd_repeat' => '123456'
 		];
 		];
-		$this->Users->patchEntity($user, $data);
+		$user = $this->Users->patchEntity($user, $data);
 		$is = $this->Users->save($user);
 		$is = $this->Users->save($user);
 		$this->assertFalse($is);
 		$this->assertFalse($is);
 
 
@@ -408,16 +408,16 @@ class PasswordableBehaviorTest extends TestCase {
 		$user->setAccess(['id'], true); // Allow id to be accessible by default
 		$user->setAccess(['id'], true); // Allow id to be accessible by default
 		$user = $this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 		$user = $this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 
 
-		$this->assertNotSame($is['password'], $user['password']);
+		$this->assertSame($userCopy['password'], $user['password']);
 		$this->assertTrue($user->isDirty('pwd'));
 		$this->assertTrue($user->isDirty('pwd'));
 
 
 		$options = ['validate' => true];
 		$options = ['validate' => true];
-		$is = $this->Users->save($user, $options);
-		$this->assertTrue(!empty($is));
+		$this->Users->saveOrFail($user, $options);
 
 
 		$user = $this->Users->get($uid);
 		$user = $this->Users->get($uid);
+
 		// The password is updated, the name not
 		// The password is updated, the name not
-		$this->assertSame($is['password'], $user['password']);
+		$this->assertNotSame($userCopy['password'], $user['password']);
 		$this->assertSame('xyz', $user['name']);
 		$this->assertSame('xyz', $user['name']);
 
 
 		// Proof that we manually need to add pwd, pwd_repeat etc due to a bug in CakePHP<=2.4 allowing behaviors to only modify saving,
 		// Proof that we manually need to add pwd, pwd_repeat etc due to a bug in CakePHP<=2.4 allowing behaviors to only modify saving,
@@ -459,7 +459,6 @@ class PasswordableBehaviorTest extends TestCase {
 		$result = $this->Users->save($user);
 		$result = $this->Users->save($user);
 		$this->assertTrue(!empty($result));
 		$this->assertTrue(!empty($result));
 		$userCopy = clone($user);
 		$userCopy = clone($user);
-		$uid = $user->id;
 
 
 		$this->Users->addBehavior('Tools.Passwordable', ['current' => true, 'require' => false]);
 		$this->Users->addBehavior('Tools.Passwordable', ['current' => true, 'require' => false]);
 		$user = clone($userCopy);
 		$user = clone($userCopy);
@@ -496,11 +495,12 @@ class PasswordableBehaviorTest extends TestCase {
 		$user->setAccess(['id'], true); // Allow id to be accessible by default
 		$user->setAccess(['id'], true); // Allow id to be accessible by default
 		$user = $this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 		$user = $this->Users->patchEntity($user, $data, ['fields' => ['id']]);
 
 
-		$this->assertNotSame($is['password'], $user['password']);
 		$this->assertTrue($user->isDirty('pwd'));
 		$this->assertTrue($user->isDirty('pwd'));
+		$this->assertSame($userCopy['password'], $user['password']);
 
 
-		$is = $this->Users->save($user);
-		$this->assertTrue((bool)$is);
+		$user = $this->Users->saveOrFail($user);
+		$this->assertNotSame($userCopy['password'], $user['password']);
+		$this->assertFalse($user->isDirty('pwd'));
 	}
 	}
 
 
 	/**
 	/**

+ 4 - 2
tests/TestCase/Model/Table/TableTest.php

@@ -5,6 +5,7 @@ namespace Tools\Model\Table;
 use Cake\Datasource\ConnectionManager;
 use Cake\Datasource\ConnectionManager;
 use Cake\I18n\Time;
 use Cake\I18n\Time;
 use Cake\ORM\TableRegistry;
 use Cake\ORM\TableRegistry;
+use Cake\ORM\Entity;
 use Tools\TestSuite\TestCase;
 use Tools\TestSuite\TestCase;
 
 
 class TableTest extends TestCase {
 class TableTest extends TestCase {
@@ -92,10 +93,11 @@ class TableTest extends TestCase {
 	 */
 	 */
 	public function testFindFirst() {
 	public function testFindFirst() {
 		$result = $this->Users->find('first', ['conditions' => ['name LIKE' => 'User %']]);
 		$result = $this->Users->find('first', ['conditions' => ['name LIKE' => 'User %']]);
-		$this->assertEquals('User 1', $result['name']);
+		$this->assertInstanceOf(Entity::class, $result);
+		$this->assertSame('User 1', $result['name']);
 
 
 		$result = $this->Users->find('first', ['conditions' => ['name NOT LIKE' => 'User %']]);
 		$result = $this->Users->find('first', ['conditions' => ['name NOT LIKE' => 'User %']]);
-		$this->assertNotEquals('User 1', $result['name']);
+		$this->assertNull($result);
 	}
 	}
 
 
 	/**
 	/**