[lang-ref] ( move_file_to_directory ) ( php )

<?php
#[WithoutErrorHandler]
public function testMoveFileToDirectory(): void
{
	// rename($src, $dst)
	touch('file1.txt');
	mkdir('dir1');


	set_error_handler(
		static function (int $errno, string $errstr) use (&$captured): bool {
			$captured = [$errno, $errstr];
			return true; // mark as handled (for test)
		},
		E_WARNING
	);

	try {
		$r = rename('file1.txt', 'dir1/');
		$this->assertFalse($r); // rename to directory is not supported
	} finally {
		restore_error_handler();
	}

	$this->assertTrue(file_exists('file1.txt')); // ensure not moved
	$this->assertFalse(file_exists('dir1/file1.txt'));

	$this->assertSame(E_WARNING, $captured[0]); // warning occurred
	$this->assertStringContainsString('Is a directory', $captured[1]); // warning message
}

function testUmask(): void
{
	// umask($mask)
	$orgMask = umask(0022);
	touch('file1.txt');
	mkdir('dir1');

	$this->assertSame(0644, fileperms('file1.txt') & 0777); // default permissions
	$this->assertSame(0755, fileperms('dir1')      & 0777); // default permissions

	umask($orgMask);
}